wxCheckListBox leaks

BlitzMax Modules Forums/Brucey's Modules/wxCheckListBox leaks

I seem to have uncovered a leak in wxCheckListBox (running in XP). I'd really appreciate it if others could run this code to confirm.

I'm getting a steady 20K leak in task manager - with the GCMemAlloced() printout looking fine.

Worse, if I comment out Clear() and uncomment the DeleteItem() code the leak remains, and the app auto-exits to desktop with nary a complaint after 250 iterations! Most unsettling...

All help much appreciated! Perhaps there's something wrong with my code?

SuperStrict

Framework wx.wxApp
Import wx.wxFrame
Import wx.wxCheckListBox
Import wx.wxTimer
Import BRL.StandardIO

Type MyApp Extends wxApp

	Field Window:TWindow
		
	Method OnInit:Int()
		Window = TWindow(New TWindow.Create( Null, , "Test CheckListbox leaks" ,,,150,150))
		Window.Centre()
		Window.Show(True)
		Return True
	End Method

End Type

New MyApp.run()

Type TWindow Extends wxFrame

	Field Timer:TTimer
	
	Method OnClose(_event:wxCloseEvent)
		If Timer
			Timer.Stop()
			Print "Timer stopped"
		EndIf		
		_event.Skip()
	End Method

	Method OnInit()
		Timer = New TTimer.CreatewxTimer(Self)
		Timer.Start(1)
		Connect(GetId(),wxEVT_CLOSE_WINDOW, _OnClose)
	End Method

	Function _OnClose(_event:wxEvent)
		TWindow(_event.parent).OnClose(wxCloseEvent(_event))
	End Function
 
EndType

Type TTimer Extends wxTimer
	
	Field List:wxCheckListBox
	Field Window:wxFrame
	
	Method CreatewxTimer:TTimer(_window:wxFrame)
		Window = _window
		Super.Create()
		Return Self
	End Method
	
	Method Notify()
	
		Global loop_counter:Int = 0
							
		' Populate the listbox
		Local s_items:String[] = ["one","two","three","four","five"]
	
		List = New wxCheckListBox.Create(Window,wxID_ANY,Null,0,0,100,100)
	
		'	Populate list
		For Local item:Int = 0 Until s_items.length
			List.Append(s_items[item],"user data_"+item)
		Next
					
		List.Clear()
	
	'	This also leaks - but worse - throws us back to desktop with no error	after 250 iterations
	'	For Local item:Int = 0 Until List.GetCount() List.DeleteItem(item) Next
				
		Print "iteration " +loop_counter +" " +GCMemAlloced()
		loop_counter :+ 1

		List.Destroy()
		List = Null
		
	End Method
	
End Type


hmm seems to happen here too, on Vista. Looking at the description for destroy it says that they're added to a list to be removed at idle time after all events are processed but it seems they not for some reason. I wonder if this is for anything that extends wxwindow or some something specific to do with the listboxes?

Mine didn't crash though after doing what you said.

Incidentally your example wouldn't run before importing brl.standardio for the print command.

Thanks for checking Pete. I've added that extra Import.

If I comment out the .Append line the leak vanishes - so the actual listbox control is being destroyed I think, just not its contents. User data doesn't seem involved as Appending with a NULL second arg still leaks.

Edit:

I can add that simply creating/populating and destroying a CheckListBox in a closed loop doesn't leak when I attempt this in C++ as follows:

for(int loop = 0; loop < 10000; loop ++){
   CreateGUIControls();
   FillCheckListBox();
   Show(true);
   ClearCheckListBox();
   DestroyCheckListBox();
   printf("%d",loop);
}


Which suggests to me there's not any issue with wxWidgets not having space/time to call its low level cleanup code.

Just a follow-up on this.

My current workaround has been to write my own CheckListBox simply by extending wxListCtrl and manually setting an empty box image/ticked box image for each row via the imagelist functionality.

You then use wxListItem.GetImage to test the check state of any given row - so you don't even need to add any extra data structures.

The result is leak free and nigh indistinguishable from the real control.