Hey - I wonder if this is too dodgy…
I have a component that makes children, and holds the pointer:
Then makes new with .reset( new etc) then makes visible.
When each child control has done its job - currently - I call a parent function (from the child’s buttonlistener) which just makes a new component, resetting the controls.
To my surprise, that works… but I’m realizing that I never did removeChildComponent() on it. The docs seem to indicate I can do that?
How bad is this? Memory leak? Or are components smart enough to deal with it?
Background - trying to use Juce in a RAD manner, doing the obvious and quick thing, not a whole bunch of architecting
Seeing as how components just store their children using an array of raw pointers I think you’ll want to call removeChildComponent() before deleting the component. Otherwise you may have a dangling pointer (via this internal array) to the child that was deleted. Have you gotten a crash or anything?
Is this just a single instance of std::unique_ptr<Component> or one per control?
You’d think so, but docs for removeChildComponent():
“Note that removing a child will not delete it! But it’s ok to delete a component without first removing it - doing so will automatically remove it and send out the appropriate notifications before the deletion completes.”
No crashes, nope. No reported leaks.
I’m using this like a poor-man’s tab control. Working so far.