Virtual Memory with mosaic

voodoochile

New member
Joined
Dec 9, 2003
Messages
2
I have written a program in VB.Net that essentailly can create a mosaic picture. It opens the smaller tile pictures, does some processing, and then weaves the smaller tiles into the larger mosaic picture. The program works fine except that with large images (over about 2000x2000 pixels), I get an "Out of Memory Error".

I am running the program on a Windows 2K, P4, with 512MB of RAM and the VM set at about 1.5GB. As I watch in the Performance section of the Task Manager, the program usually only takes about 20MB, but the VM obviously is out of control.

I am using 2 graphics objects and 2 bitmap objects as I shuffle the images around in processing. In each pass through the loop building my mosaic, I am using a:

graphics = nothing
graphics.dispose()
-- or a --
bitmap = nothing
bitmap.dispose()

So I think I am releasing my stored resources. What can be done to either be more efficient with clearing the memory or using the variables in a cleaner way?
 
I added some code to force garbage collection after every 20th tile:

If i / 20 Mod 0 Then
GC.Collect()
End If

Is this a bad practice?
 
Hi voodoochile,
try doing the bitmap.dispose before the bitmap = nothing etc.. and see if this helps. I would leave the GC.collect call as well.
 
Dont you have to dispose it before you release the reference so that it has a reference to the resources that you are trying to dispose of?
 
Back
Top