GC does not delete subclass

Steven Schveighoffer schveiguy at yahoo.com
Tue Dec 18 07:21:06 PST 2007


"Jason House" wrote
> 0ffh Wrote:
>
>> Matthias Thurau wrote:
>> > thanks for replys...
>> >
>> > So how do i handle this? Should i ignore that or am i doing something 
>> > wrong? (Ist it a bug or not? :)
>>
>> Ignore it. Most probably no bug!
>> Who has ever claimed that the GC collects objects in any specific order?
>
> I don't think it was specifically the order but rather full collection not 
> fully collecting.
>
> I haven't tried this, but is it possible to declare class member variables 
> as scope so that they will get deleted when the rest of the object does? 
> This could save coding of custom destructors in some cases.

Custom destructors should NEVER destroy other GC allocated objects.  the GC 
cannot guarantee the order of collection, meaning if you have a pointer to 
another GC allocated object, that object may have already been collected.

There is no real reason to delete other objects in a destructor.  If the 
objects are no longer referenced, the GC will destroy those also.  The only 
things you should destroy in a destructor are non-GC allocated resources, 
such as file descriptors, or memory allocated with C's malloc.

So to answer your question: scope is not necessary as a modifier for a 
member variable.

-Steve 





More information about the Digitalmars-d mailing list