On Friday, 25 May 2012 at 14:35:58 UTC, Andrei Alexandrescu wrote:

What happens in C# if an object A that has a field referring to object B, and the object B has in turn a field referring to object A? That is:

class C { C another; ~this() { writeln(another.another); } }

void main() {
    auto a = new C;
    auto b = new C;
    a.another = b;
    b.another = a;
}

What happens then? Will the GC nullify references to destroyed objects, or will it put them in a zombie state?


Thanks,

Andrei

In this case the a and b objects will be collected by GC and memory freed. It's a one of most popular questions about .NET GC. Maybe something was changed in .NET >= 4.5.

I have another question: there available a good example of idiomatic destructor usage in the D?
Something without calling a rt_ hooks on destroy?

Reply via email to