Notifications
Clear all

[Closed] bitmaps in dotNet…memory leaking?

When a dotNet listView, treeView, contextenuStrip, etc, uses bitmap icons, they are never removed from memory. Each time the dialog is created they will load again. It makes no difference if the dotNet items are local, global, made undefined.
Max or dotNet garbage collection also doesn’t seem to help.
I noticed it when I tried loading pretty large bitmaps for a test and after a few times restarting the script, the 3dsmax.exe process ran out of memory.
Anyone noticed that, or got a solution?

Marc

5 Replies

Hi Artur,

Interesting…you said you could fix it by using picturebox.load instead of picturebox.image?
I don’t follow you here, but i found another solution:

		
on my_rollout close do
 		(
 			for i =0 to (contextMenuItems.count-1) do 
 				(
 					contextMenu.Items.item[i].image.dispose()
 				)
 		)

each image item has to be disposed manually, otherwise it will stay in memory.

this link helped me finding the solution:
http://stackoverflow.com/questions/1831732/c-picturebox-memory-releasing-problem

Hey Marc,
Sorry I wasnt quite clear… I manage to overcome that problem by writing a custom picturebox class The Load method did seem to work but I was wrong

And I remember writing a custom GC function… dunno, it’s been a long time but I’m glad you got it working!

Cheers.

Hello Marc,

I’ve had the same problems before and tried all sorts of combinations of garbage collection, max and .NET. Finally I figured out that I first had to dispose the imagelist of a control (a listview in this example). After that the garbage works just fine. This method may be a bit quicker than doing it for every image individually.

try(myListView.largeImagelist.dispose())catch() --first dispose of the imagelist
 -- Garbage collection frees up the resources after disposing them.
 local dgc = dotnetclass "system.gc"
 dgc.collect()
 gc()

Klaas

Hi Klaas,

thanks. I’ll try that!