Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development
ClearCase Plug-In
thomas:
--- Quote from: killerbot on October 30, 2005, 05:54:38 pm ---I allocate my wxMenu (for the submenu) now at constructor time
--- End quote ---
Not good. When the popup menu is closed, your wxMenu is freed. Allocate inside BuildModuleMenu.
killerbot:
So that means that if you allocate a submenu, you don't need to free/delete it in case of the "context menu", this is done automatically ??
Does this also apply for submenus generated in an exisisting menu (for example a submenu one has created and addedt to let's say the "Edit" menu ??
Trying out your hint right now.
Thanks,
lieven
killerbot:
Thanks Thomas,
It works. Good to know this, since it is a bit surprising that you loose ownership.
It is strange that I did not get a crash when I close cb, since in my destructor I checked my 'sub'menu pointer, and if it is still != NULL I delete it. So taking into account your words, I would have been a second delete.
This whole stuff might be dangerous, since I allocate (in my dll), it get's freed in another dll/exe I guess, the application in charge of the menu ?? What if both are build differently, release build <---> debug build. I know for example in M$ Dev Studio, one had to make sure alloc/free had to originate from the same flavour(debug,release, single/multi-thread).
As I see it here, this danger is lurking at us.
I think it would have been better that the Append/Insert/Prepend of a submenu would have been done by a pointer pointer, in that way you could check on the 'pointer' to be NULL or not, so if it got allocated by someone else they could have set the value of the pointer to NULL, and one could check through *pointerpointer. Pff, always suspicous for memory leaks. :?
Or event better, if you want to append a (sub)menu, wx could create it on the inside, then ownership did not have to be transfered, and alloc/free could happen in the same environment. And you could get a handle back for adding the entries.
But these are wx issued not cb's.
kind regards,
Lieven
thomas:
--- Quote from: killerbot on October 30, 2005, 06:51:12 pm ---So that means that if you allocate a submenu, you don't need to free/delete it in case of the "context menu", this is done automatically ??
--- End quote ---
Never delete anything that you pass to a wxWidgets GUI container (and your menu is passed to wxWidgets in the end, obviously).
This is not only unnecessary, it is detrimental, because the same object may be freed twice, which is an undefined operation.
Edit:
In almost every case, you can pass an object to wxWidgets, and it will make silently a copy for its own. There are very few exceptions (and unluckily, I don't remember them). That way, you have your object on the stack and don't need to care about allocation anyway, when it goes out of scope, it's gone.
rickg22:
--- Quote from: thomas on October 30, 2005, 07:53:10 pm ---This is not only unnecessary, it is detrimental, because the same object may be freed twice, which is an undefined operation.
--- End quote ---
Yeah. We've had MANY crashing problems with Codeblocks because of objects deleted twice. Have to be VERY VERY careful there.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version