moke123
AWF VIP
- Local time
- Today, 03:06
- Joined
- Jan 11, 2013
- Messages
- 3,913
In order to tightly control a data entry procedure I am using a custom class. Within the class I am instantiating several popup forms with withevents for several controls on the forms.
Everything works perfectly so far except for the Class_Terminate event. I declare the class in the forms declarations and instantiate and initialize it with a button click. I put a messagebox in the terminate event to confirm it is firing. The problem is that it fires several times. If I specifically fire it in my class I get the messagebox. If I then run the class again it fires first before the class executes, again when called in the class and again when I close the form.
Researching the issue it seems to be related to a memory leak when using withevents within the class. Something about the cleanup routine failing to clean up all the objects having to do with scope. I've double checked that I set all the objects to nothing in the terminate procedure but it appears to leave some in memory. When I close the form it appears to clean everything up.
Is there an easy way to stop the leaks? As a workaround I am opening a hidden form and declaring and initializing the class in the hidden form. At the competion of my procedure I close the hidden form which fires the terminate event and appears to be cleaning up all the objects as the terminate event only fires one time.
Is this a valid work around?
Everything works perfectly so far except for the Class_Terminate event. I declare the class in the forms declarations and instantiate and initialize it with a button click. I put a messagebox in the terminate event to confirm it is firing. The problem is that it fires several times. If I specifically fire it in my class I get the messagebox. If I then run the class again it fires first before the class executes, again when called in the class and again when I close the form.
Researching the issue it seems to be related to a memory leak when using withevents within the class. Something about the cleanup routine failing to clean up all the objects having to do with scope. I've double checked that I set all the objects to nothing in the terminate procedure but it appears to leave some in memory. When I close the form it appears to clean everything up.
Is there an easy way to stop the leaks? As a workaround I am opening a hidden form and declaring and initializing the class in the hidden form. At the competion of my procedure I close the hidden form which fires the terminate event and appears to be cleaning up all the objects as the terminate event only fires one time.
Is this a valid work around?