Classes

J

JonWayne

If you destroy an instance of a class that has children obects defined
within, do the child objects go south with the parent?
 
J

JonWayne

Just to rephrase a little: let say the children objects are set with the NEW
keyword and become alive with the use of 1 or more properties or methods -
in which case, pointers are created. Do the kids get destroyed simply thru
the destruction of the parent, or do their pointers keep them alive?

thanks
 
J

John Nurick

What happens when you try?

Just to rephrase a little: let say the children objects are set with the NEW
keyword and become alive with the use of 1 or more properties or methods -
in which case, pointers are created. Do the kids get destroyed simply thru
the destruction of the parent, or do their pointers keep them alive?

thanks
 
W

Wolfgang Kais

Hello JonWayne

JonWayne said:
If you destroy an instance of a class that has children obects
defined within, do the child objects go south with the parent?

An Object is destroyed when all variables that reference it are set to
Nothing or are beyond scope.
If your "parent" also has a "friend" that knows it's "child" (a reference
to that child that is stored outside the parent's class), you should use
the terminate event of the parent to erase the friend's memory for
making the child go west too (Set VarOrPropOfFriend = Nothing).
 
G

Graham R Seach

Jon,

The theory is that, if references to the child objects are declared in the
parent object, then when you destroy the parent object, the reference
variables go out of scope, and thus so do the references to the child
objects. By inference, this means the child objects will be destroyed.

All assuming, of course, that you don't have circular references, in which
case, all bets are off.

The best course of action is to create a public Dispose method in each
object class, which explicitly destroys any references the object may have
created, including circular ones. You can call the Dispose method from the
class's Terminate event.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top