Garbage Collection and Containment

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am curious about the following scenario concerning C# classes A and B

class

A(


void method1(

method2()
method3()

void method2(

b = new B()

void method3(

b = new B()

B b


Is the first instance of B created in the call to method2() garbage collected or does it LEAK

Thanks
Eagle (C++ guy learning C#)
 
Hi..

It is garbage collected. The reference "b" switches from the first instance
to the second instance, abandoning the first instance. This "abandoned"
instance is collected.

John
 
Back
Top