P
Petros Amiridis
Hi,
When I create an instance of one of my classes inside a method, does it
make a difference if I call its Dispose method?
public class Foo : IDisposable
{
public Foo
{
}
public Foo anotherFoo = null;
public void Dispose()
{
}
}
Given the class above is there a difference between the two examples
below? When will the GC give back the memory? Does ExampleA confuse GC
when it comes to tracking and releasing foo2?
public void ExampleA()
{
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Foo foo3 = new Foo();
foo1.anotherFoo = foo2;
foo1.anotherFoo = foo3;
}
public void ExampleB()
{
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Foo foo3 = new Foo();
foo1.anotherFoo = foo2;
foo2.Dispose();
foo1.anotherFoo = foo3;
foo1.Dispose();
foo3.Dispose();
}
Thanx,
When I create an instance of one of my classes inside a method, does it
make a difference if I call its Dispose method?
public class Foo : IDisposable
{
public Foo
{
}
public Foo anotherFoo = null;
public void Dispose()
{
}
}
Given the class above is there a difference between the two examples
below? When will the GC give back the memory? Does ExampleA confuse GC
when it comes to tracking and releasing foo2?
public void ExampleA()
{
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Foo foo3 = new Foo();
foo1.anotherFoo = foo2;
foo1.anotherFoo = foo3;
}
public void ExampleB()
{
Foo foo1 = new Foo();
Foo foo2 = new Foo();
Foo foo3 = new Foo();
foo1.anotherFoo = foo2;
foo2.Dispose();
foo1.anotherFoo = foo3;
foo1.Dispose();
foo3.Dispose();
}
Thanx,