My application spawns several independent forms. Once when created the application forgets about them. All action is handled in that form itself. When the application closes the form closes also, by the RTS i suppose. This is fine except that neither the OnClose nor the OnDestroy event are being fired, so memory leaks occur. I can administer which forms are present (as i do now) but actually the application must completely forget about these forms.
Is there a way to detect inside a form, being not the application main form, that the application is in the process of being closed?
The
OnDestroy
event certainly will fire if the form is destroyed. It's invoked from the form's destruction code. So the only conclusion is that your form is not being destroyed and so is leaked.There are a couple of obvious ways to make sure that your independent forms are not leaked:
Application
orMainForm
as the owner parameter of the form. When the owner is destroyed, it will also destroy everything it owns, including your forms.Application.Run
returns.Option 1 is the most commonly used approach.