General wisdom is when you remove a component from the stage you also need to manually remove all children so they are not floating in memory. Because they are just none visible since the parent container was removed.
Example of this would be a Label component inside of a BorderContainer. My understanding is you need to remove the Label first then the BorderContainer.
When you create a component such as TitleWindow the default skin for it adds a closeButton to the title bar / header.
I added an event listener to the close button. TitleWindow.closeButton.addEventListener(); In the function called by the close button event i want to close/remove the window.
My question is this. Do i need to manually remove the closeButton as a child of the TitleWindow? Or do i just remove the listener then remove the TitleWindow from the stage and the components created by the skin are automatically removed / garbage collected?
If a component is removed from the stage, all of its children will automatically be removed and garbage collected as long as you’ve removed al event listeners. So you don’t need to explicitly remove the children in order for them to be garbage collected.
BUT in your question you refer to skins. When skins are used their host component’s
skinDestructionPolicyproperty is always set tonever(that is except for one mobile class; I forgot which one). This means that a skin and all of its children will simply stay in memory forever and never get garbage collected.Now the not-so-happy part: it is not easy to override this default setting. Read this question and the answer I’ve written there to see how it can be done: Spark SkinnableComponent skinDestructionPolicy
Note that in 99% of the cases this default behaviour is really not an issue. Of course I do not know your specific situation, so I can’t comment any further on that.