Leak memory when I remove wxMenu
BlitzMax Forums/Brucey's Modules/Leak memory when I remove wxMenu
| ||
the part where I remove the wxMenu: I don't know where it leak but if I don't use any wxMenu code no memory is leaking! So obvious the leak is here: Repeat Local m:wxMenu If MBar.GetMenuCount() Then m = MBar.Remove(0); m.Free() ' I don't believe in this! ' If MBar.GetMenuCount() Then MBar.Remove(0) Until Not MBar.GetMenuCount() For Local q:Int = 0 To MenuItm.Length-1 If MenuItm[q].Menu Then MenuItm[q].Menu.Free() MenuItm[q].Menu = Null MenuItm[q] = Null Next MenuItm = NullI think MBar.Remove(0) is my leak, but I don't know howto stop the leak My Question is how can I delete a wxMenu menu properly? |
| ||
as I suspect i is ONLY a copy:Local s:String[] = ["ett", "tva", "tre"] Print "0: " + s[0] + " 1: " + s[1] + " 2: " + s[2] For Local i:String = EachIn s echo "this: " + i i = Null Next Print "0: " + s[0] + " 1: " + s[1] + " 2: " + s[2]This did Nothing ^^: If MBar.GetMenuCount() Then m = MBar.Remove(0); m.Free() I try to Destroy all the MenuItems but it still leak around 12500 bytes every time I remove the menu: Local ii:wxMenuItem[] = MenuItm[q].Menu.GetMenuItems() For Local i:wxMenuItem = EachIn ii MenuItm[q].Menu.Destroy(i.getID()) Nextwx.mod\wxmenubar.mod\wxMenubar.bmx: Rem bbdoc: Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it. about: This method may be used together with wxMenuBar::Insert to change the menubar dynamically. End Rem Method Remove:wxMenu(pos:Int) Return wxMenu._find(bmx_wxmenubar_remove(wxObjectPtr, pos)) End MethodThis make my headache: "the caller is responsible for deleting it" |
| ||
Hi, taken from the menu sample program there is a example function to delete menuitem: Function OnDeleteMenuItem(event:wxEvent) Local menubar:wxMenuBar = MyFrame(event.parent).GetMenuBar() Local menu:wxMenu = menubar.GetMenu(menubar.GetMenuCount() - 1) Local count:Int = menu.GetMenuItemCount() If Not count wxLogWarning("No items to delete!") Else menu.DestroyItem(menu.GetMenuItems()[count - 1]) End If End Function -Henri |