GC does not delete subclass
Sean Kelly
sean at f4.ca
Tue Dec 18 11:53:46 PST 2007
Steven Schveighoffer wrote:
> "Matthias Thurau" wrote
>> "If the objects are no longer referenced, the GC will destroy those also."
>>
>> Thats exact the case: In my example the GC isn t destroying that
>> unreferenced member.
>
> My understanding of scope is that the object is supposed to be forcefully
> deleted at the end of the scope (not through the GC). So in your case, I
> believe there is a bug, because delete should call the destructor
> immediately. i.e.:
>
> {
> scope C = new C;
> }
>
> should be equivalent to:
>
> {
> auto C = new C;
> delete C;
> }
>
> So I believe that the GC shouldn't be calling the destructor in fullcollect,
> it should be called BEFORE fullcollect is called.
I'm pretty sure that this is what's happening. However, it is only
deleting C, not the objects that C points to. This is necessary
behavior. Consider:
class A
{}
class B
{
this( A a )
{
val = a;
}
A val;
}
void fn( A val )
{
scope B = new B( val );
}
You certainly wouldn't want the instance of A deleted when fn exits as well.
Sean
More information about the Digitalmars-d
mailing list