Freeing an IconStrip

BlitzMax Forums/MaxGUI Module/Freeing an IconStrip

DavidDC(Posted 2007) [#1]
Are iconstrips being properly released from listbox (and potentially other) gadgets?

The following code produces interesting results on both Leopard (1.28) and XP (1.26)

Via process memory watch, XP process memory hits a ceiling of about 141 Mb - whereas Leopard didn't have a ceiling although I did stop watching at around 300Mb. I don't know about you, but 141 Mb seems like a pretty late kick in for the GC.

Or perhaps there's a "ReleaseIconStrip" function that I'm overlooking?

Can others verify this behaviour?

Strict

Global panel:TGadget
Global listbox:TGadget
Global window:TGadget

window=CreateWindow("Leak tester", 40,40,800,800,,WINDOW_RESIZABLE|WINDOW_TITLEBAR|WINDOW_STATUS)

Local i:Int
	
Repeat
	
	Panel = CreatePanel(0,0,600,600,window)

	'	Listbox
	listbox = CreateListBox(0,0,100,100,Panel)
	Local icon_strip:TIconStrip = LoadIconStrip(BlitzMaxpath()+"/src/maxide/icons.PNG")
	
	SetGadgetIconStrip(listbox, icon_strip)

	For  i = 0 Until 100
	
		AddGadgetItem listbox,"item " +i,GADGETITEM_NORMAL,i Mod 5
	
	Next

	FreeGadget listbox
	listbox = Null
	icon_strip.pixmap = Null
	icon_strip = Null
	FreeGadget Panel
	
	 PollEvent()
	If CurrentEvent And CurrentEvent.id = EVENT_WINDOWCLOSE Then End
	
	SetStatusText window, "GC says... " +GCMemAlloced()
	
Forever


Thanks

-David


remz(Posted 2007) [#2]
Hi, I tested your app on my mac tiger with bmax 1.28, and it does indeed seem to leak resources out of the GC knowledge. (side note: pressing ESCAPE does not stop the application as intented: in a GUI app, one should rely on events, not polled input)

If you change your loop to 'repeat..forever' and add this code at the end of the loop:
	PollEvent()
	If CurrentEvent And CurrentEvent.id = EVENT_APPTERMINATE Then End

	GCCollect()
	DebugLog "GCMemAlloced="+GCMemAlloced()
	
Forever

You'll see that the garbage collector is not leaking a byte. Perfectly steady. (afaik, you still need to call GCCollect() once in a while else it will wait until fairly large amount of memory is used before freeing)
The Real Memory value in Activity Monitor definitely shows a slow leak of about 1-2 MB per second, probably image resource inside Aqua or anyhow untracked by Bmax' GC.


DavidDC(Posted 2007) [#3]
Hi remz,

Yes sorry I was being very lazy re the exit code. I've updated it now, thanks. And yes the leak, like most of the leaks Brucey has been patching, is below the max layer and undetected by GC.

Still very much there though! What happens on 1.28 win32 I wonder?


Gabriel(Posted 2007) [#4]
What happens on 1.28 win32 I wonder?

Much the same as you've described above. I couldn't tell you if and when it stopped as it started making windows run very badly before that. The app vanished and then the screen went white, alt-tab stopped working and I had to fiddle and faff about to even be able to shut it down. But yeah, still happening.


DavidDC(Posted 2007) [#5]
Sounds nasty Gabriel! Thanks for testing.

Before I start crying "It's da Wooluf" in earnest then, can we confirm that the test code is itself OK?

- David