472,125 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

ListView and ImageList hogging memory - what to do?

I am working on an application that includes a feature where a
directory is spidered and thumbnails are displayed. I have it pretty
much down, but when the bitmaps are loaded from file, memory is hogged
like crazy. I know this is where the memory problems occur because
I've gone through that whole comment/check the ram thing. Here's the
source of where the problem occurs:

Public Shared Sub FillImageList(ByVal dir As String, ByVal ListView As
ListView)
If Directory.Exists(dir) Then
'Get the files in an array and
'figure out how many there are
Dim file As String
Dim files() As String = Directory.GetFiles(dir)
Dim cleanfiles(files.Length) As String
Dim i As Integer = 0
For Each file In files
If Regex.IsMatch(file.ToString,
"[^<.*>.*](.jpg|.JPG|.jpeg|.JPEG|.png|.PNG|.gif|.GIF|.tif|.T IF|.bmp|.BMP)")
Then
cleanfiles(i) = file.ToString
i = i + 1
End If
Next

'Create a thumbnail for every image and add it to the
imagelist
If cleanfiles.Length > 0 And cleanfiles(0) <> "" Then
Dim h As Integer = 0
For Each file In cleanfiles
If file <> "" Then
'###BEGIN MEMORY LEAK
Dim objImage As Image
' Open the image
objImage = New Bitmap(file)
'###END MEMORY LEAK

' Convert the image to a thumbnail. This is
faster
' than the longer convert/compress to JPEG I
was
' using before.
objImage = objImage.GetThumbnailImage(100,
100, Nothing, New IntPtr)

'Add the thumbnail to the image list
ListView.LargeImageList.Images.Add(objImage)
'Add the filename as the text
ListView.Items.Add(file.ToString)
'Attach the image to the text
ListView.Items(h).ImageIndex = h
h = h + 1
objImage.Dispose()
End If

Next
End If
End If
End Sub
Any help would be very greatly appreciated. Reply here or email
pu****@putnamplanet.com. Thanks!

-C
Nov 20 '05 #1
0 2156

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Silvia | last post: by
3 posts views Thread by Ian | last post: by
reply views Thread by Silvia | last post: by
1 post views Thread by Steve | last post: by
4 posts views Thread by Archimed | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.