Understanding the GC
Maxim Fomin
maxim at maxim-fomin.ru
Wed Jan 30 04:17:32 PST 2013
On Wednesday, 30 January 2013 at 12:08:07 UTC, monarch_dodra
wrote:
> On Wednesday, 30 January 2013 at 11:57:01 UTC, Maxim Fomin
> wrote:
>> On Wednesday, 30 January 2013 at 10:29:26 UTC, monarch_dodra
>> wrote:
>>> On Wednesday, 30 January 2013 at 08:15:15 UTC, Mike Parker
>>> wrote:
>>>> Destructors of members will not be called when an object is
>>>> collected. Only that of the object itself. But, there's no
>>>> guarantee that any member references will still be valid
>>>> when the object's destructor is called. See below for more.
>>>
>>> Just to be clear, I suppose you (both) are talking about
>>> "member references"? EG: Nested classes?
>>
>> I found calling member class references as nested classes
>> confusing - they are very different.
>>
>>> Destroying an object 100% guarantees its member destroyers
>>> are also called, outer to inner, first in first out, as part
>>> of the destruction process. The thing is that when you store
>>> a "class reference" then you call the destructor of the
>>> reference itself. References being glorified pointers, it
>>> basically means it does nothing.
>>
>> Are you implying that in following code snippet:
>>
>> class A { ~this() { ... } }
>> class B { A a; ~this() { ... } }
>>
>> destructor of A will be always called after B, so "a" member
>> is always accessible in B's dtor?
>
> No. What gave you that idea? I said the "reference" a will be
> destroyed (set to null). The actual referenced "class instance"
> may or may not be destroyed by then. The class instance of A
> itself is not a member of B.
English is not native for me. Sometimes non-natives misunderstand
the meaning of the words.
More information about the Digitalmars-d-learn
mailing list