[wxMenu] delete manualy popup menu?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

[wxMenu] delete manualy popup menu?

Post by MoonKid » Fri Mar 04, 2011 1:48 am

If I understand this right
http://docs.wxwidgets.org/trunk/classwx_menu.html

I have to destroy wxMenu objects on the heap by myself when I use them with wxWindow::PopupMenu(). Right?

If I don't do this I see the dump-object while debuging.

But If I do a 'delete pMenu_' I recieve an error while debuging (access violation). It looks like that the object isn't still there.

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Fri Mar 04, 2011 9:53 pm

The idea is that the function wxWindow::PopupMenu does not take ownership of the menu given in argument. Once the function returns, the menu is no more used.

So, you can allocate your menu on the heap, and use it multiple times with this function, and delete it when you do not need it anymore.

But you can also create it on the stack if you directly initialise it where you use it. In this case, you do not need to destroy (you cannot in fact...) it as it will be destroyed by the Cpp runtime when the function will exit.
But If I do a 'delete pMenu_' I recieve an error while debuging (access violation).
If possible, post your code so that we will be able to check what is going wrong..

Post Reply