Destructor called when? (Real Studio network user group Mailinglist archive)
|Re: recordset's recordcount - Jan Erik Moström <|
|Destructor called when? - Christian Schmitz|
|Re: Destructor called when? - Joseph J. Strout|
|Destructor called when?|
|Date: 27.08.02 23:24 (Wed, 28 Aug 2002 00:24:57 +0200)|
|From: Christian Schmitz|
I've just made a small testing project.
It looks like the destructor is not called directly, but some time
Just two classes (class1 and class2) with properties:
property window1.c as class1
property class1.d as class2
if c=nil then
msgBox "c is now nil."
msgBox "c is not nil."
msgBox "class1 destructor done."
msgBox "class2 destructor done."
Now I set the reference to d to nil, but the detructor of class2 is
called later, so I may get in trouble.
And I'm currently with one project in real trouble because the
destruction is not done in the correct order.
Realbugs report # 87240.
|Re: Destructor called when?|
|Date: 27.08.02 23:30 (Tue, 27 Aug 2002 15:30:49 -0700)|
|From: Joseph J. Strout|
At 12:24 AM +0200 8/28/02, Christian Schmitz wrote:
>It looks like the destructor is not called directly, but some time
It's called when the last reference to the object is removed --
immediately, unless there are already objects in the process of being
destroyed (those finish first).
>Just two classes (class1 and class2) with properties:
>property window1.c as class1
>property class1.d as class2
> if c=nil then
> msgBox "c is now nil."
> msgBox "c is not nil."
> end if
> c=new class1
> d=new class2
> msgBox "class1 destructor done."
> msgBox "class2 destructor done."
>Now I set the reference to d to nil, but the detructor of class2 is
>called later, so I may get in trouble.
Sorry, I can't quite see what you mean. When you set class1.d to
nil, if that was the last reference to that object, then the class2
destructor will be called immediately or as soon as all other
condemned objects have finished being destroyed.
>And I'm currently with one project in real trouble because the
>destruction is not done in the correct order.
If you have a chain of objects all being destroyed at once, the order
is undefined. So there is no "correct" order, and you shouldn't
write code that depends on any particular order.