GC and dispose
- From: "Petros Amiridis" <petros@xxxxxxxxxxx>
- Date: Tue, 20 Jun 2006 09:52:49 -0700
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,
--
Petros
.
- Follow-Ups:
- Re: GC and dispose
- From: Markus Stoeger
- Re: GC and dispose
- From: Phil Wilson
- Re: GC and dispose
- Prev by Date: GAC problem -- can't remove an assembly
- Next by Date: Re: ClickOnce application parameters
- Previous by thread: GAC problem -- can't remove an assembly
- Next by thread: Re: GC and dispose
- Index(es):
Relevant Pages
|
Loading