I have been fooling around a bit with the concepts of Owners and Parents in component/window hierarchies and the other day I stumbled on this example from the Demo application.
The WidgetsDemo demonstrates (MiscPage) how a component may be dragged onto the desktop and become a window. This removes the component from the DemoPageComp child list and adds it to the desktop instead. When the WidgetsDemo is deleted the DragOntoDesktopDemoComp is not deleted since it is not in the child list.
I suppose you (Jules) have noticed this since DragOntoDesktopDemoComp::mouseDrag(…) includes a check that will delete the instance in case its parent is not a valid component.
By opening and closing the WidgetsDemo and dragging the little “bubble-windows” onto the desktop, it is possible to create arbitrarily many instances of the DragOnto… component and leave them on the desktop, and they are not deleted explicitly at shutdown. (You will get an exception in Desktop’s destructor).
There are several ways to deal with this, but my question is:
How do YOU propose to deal with components that are owned by a component of which they are not children, supposing that the deletion of the owner should cause these owned components to be deleted?