rbulph
07-18-2003, 01:41 PM
I am having problems with user controls not terminating correctly. Their terminate event is not triggering when I close the form that contains them, only when the whole application is terminated. I know this because I have put a debug statement in their terminated event. The result of this is that the forms that contain them do not unload properly, so that their variables are not reinitialised on reloading, even though I have "Set frmOne =Nothing". What could be causing this?
Bobo the Thief
07-18-2003, 02:14 PM
I am having problems with user controls not terminating correctly. Their terminate event is not triggering when I close the form that contains them, only when the whole application is terminated. I know this because I have put a debug statement in their terminated event. The result of this is that the forms that contain them do not unload properly, so that their variables are not reinitialised on reloading, even though I have "Set frmOne =Nothing". What could be causing this?
Every control on a form should* unload before the form unloads. Are you sure that you made the form unload (not just made in invisible)? You could put a breakpoint in the Form_Unload event also, that way you can be sure.
Your control is added to the current project group, right? Otherwise breakpoints have no effect.
*There are exceptions to what I said at the beginning. To get a full understanding of this issue, read the topic "Life Cycle of Visual Basic Forms" in MSDN. You will see there that there is a situation when you can have an unloaded form, but with one control still loaded. That happens when the component in still referenced by an object variable, that keeps it from unloading. So you must distroy all these references in order for the control to unload. However, there's no need to "Set frmOne=Nothing".
rbulph
07-18-2003, 03:20 PM
The form definitely is going through its unload event, and the user controls are all located in the project. Actually I was aware of the danger of referencing controls from outside of forms and having those references remain after you unload the form. But I cannot for the life of me find any such reference. So I'm stuck.
Thanks for your help and if you or anyone else has any other ideas then I'd be very grateful to hear them. Otherwise I'll just hope the problem goes away.
rbulph
07-21-2003, 12:05 PM
Finally found the answer after much experimenting. The user control contains a coolbar control. This is what was stopping the user control from terminating. If I set the Child control of each band in the coolbar to Nothing before unloading the form that contains the user control that contains the coolbar, then the terminate event of the user control happens. If I don’t then it seems that a new user control is created each time I show the form, and they are all kept in memory until the application terminates. So far as I’m aware that doesn’t cause any problems apart from wasting memory, but I certainly don’t like it.
This is just the latest in a long line of problems I have had with the coolbar. Think I might write my own control to replace the standard coolbar.
Thinker
07-21-2003, 01:11 PM
If you had actually set the form = Nothing after doing unload, it would
probably delete all objects related to the usercontrol and you would see
the terminate event fire. You won't see the terminate event of a form
fire from just unloading. You have to actually release all references.
rbulph
07-21-2003, 01:29 PM
If you had actually set the form = Nothing after doing unload, it would
probably delete all objects related to the usercontrol and you would see
the terminate event fire. You won't see the terminate event of a form
fire from just unloading. You have to actually release all references.
Please (re)read my first post. I do set the form to Nothing after it has unloaded, but this wasn't working.
Thinker
07-21-2003, 01:56 PM
I reread your first post, then tried it myself and I agree you are right.
As long as you set to nothing each band's child, it does terminate. I
should have tried it first before posting.