MarkK
bit cruncher
- Local time
- Today, 05:38
- Joined
- Mar 17, 2004
- Messages
- 8,443
Using non-default instances of forms can be very powerful. See Allen Browne's discussion of non-default instances, and a technique to keep them open here: http://allenbrowne.com/ser-35.html
VBA keeps a class instance alive based on reference counts, so if there is one reference to an instance, garbage collection leaves it alone, but if that last reference goes out of scope the object is quickly gobbled up. Consider this code that creates a non-default instance of a form...
This form will open for a second, become visible, but when frm goes out of scope the reference count to the Form_Form1 instance goes down to zero, and garbage collection destroys the object, reclaims the memory, and the form winks out of existence.
But the form can also maintain its own reference count with code like...
...so the form maintains an object reference to itself, VBA is fine with that, and the form stays open without any external references.
What I'm not sure of yet is whether this is a memory leak. If you close the form, it closes, but I don't have time to test if the object is released from memory or not.
Here's a sample Db too...
VBA keeps a class instance alive based on reference counts, so if there is one reference to an instance, garbage collection leaves it alone, but if that last reference goes out of scope the object is quickly gobbled up. Consider this code that creates a non-default instance of a form...
Code:
sub createform
dim frm as form
set frm = new form_form1
frm.visible = true
end sub
But the form can also maintain its own reference count with code like...
Code:
Private m_frm As Form
Private Sub Form_Load()
Set m_frm = Me
End Sub
What I'm not sure of yet is whether this is a memory leak. If you close the form, it closes, but I don't have time to test if the object is released from memory or not.
Here's a sample Db too...