all groups > dotnet windows forms > february 2004 >
You're in the

dotnet windows forms

group:

Call Image.Dispose when clearing an Image List?



Call Image.Dispose when clearing an Image List? Trev Hunter
2/14/2004 8:55:29 PM
dotnet windows forms: Hi,

I have a listview which is set to view items in a small icon view. It's set
up to get the images from an image list.

When I populate the listview, I clear the image list and add new images for
each item. This seems to work fine, but what I was wondering was if I should
call the Dispose method on the images when clearing the imagelist before
repopulating the listview?


Currently, I'm doing the following:

----------------------

' Clear the lists
lstItems.Items.Clear
ilstItemImages.Images.Clear

' Before calling clear, should I get a
' reference to the images and call
' Dispose() after calling clear?


' Add a new item
' Add a new icon for the item
.....

----------------------

Thanks for any help,

Trev.

RE: Call Image.Dispose when clearing an Image List? v-raygon NO[at]SPAM online.microsoft.com
2/16/2004 5:56:24 AM
Hi Trev,
Based on my understanding, you have some items in the list (smallicon view). Then you want to change items and icons.
From your description, do you mean that you want to apply Dispose on the Images (ImageList.ImageCollection)? Or you want to clear the images by yourself
instead of letting CLR's GC handle it.

In the first case, it is not supported.

In the second case, if it is not where you must clean up the resource or not a place where you know it is safe to do this for performance improving, I suggest you
using clear to remove all the images and masks from the ImageList and then add new icons for items .


Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.









Re: Call Image.Dispose when clearing an Image List? Trev Hunter
2/16/2004 10:03:45 AM
Hi, thanks for the tips. Let me explain a bit further what I am doing:

1) I populate the listview with a list of files
2) When I add an item to the listview, I use the API call SHGetFileInfo to
get the icon for the file type
3) I add the icon to the image list

From time to time, the list is changed (cleared an repopulated). Since I
added the individual images at runtime instead of from a resource, do I need
to call dispose() on the individual images before I call
ImageList.Images.Clear(), or will the ImageList handle disposing of the
images automatically?

Thanks again for your help,

Trev.

[quoted text, click to view]
Images (ImageList.ImageCollection)? Or you want to clear the images by
yourself
[quoted text, click to view]
not a place where you know it is safe to do this for performance improving,
I suggest you
[quoted text, click to view]

Re: Call Image.Dispose when clearing an Image List? v-raygon NO[at]SPAM online.microsoft.com
2/17/2004 10:32:06 AM
Hi Trev,
I think you don't need to apply dispose on the images. Imagelist will
handle disposing of images automatically.

If you want to clear them immediately, I suggest you using
GC.Collect() after you call the Clear().

Best regards,
Rhett Gong [MSFT]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
Please reply to newsgroups only. Thanks.









Re: Call Image.Dispose when clearing an Image List? Trev Hunter
2/17/2004 5:53:20 PM
Thanks for you're help. 'tis much appreciated.

Trev.


[quoted text, click to view]

AddThis Social Bookmark Button