Re: "forcing" garbage collection
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Mon, 26 May 2008 20:18:22 -0400
Jon Mcleod wrote:
I'm trying to wrap my ming around C#/CLR garbage collection. In an ASP.NET project, I'm having a problem because an object destructor
destructor = finalizer ?
is being called by another thread,
Some code explicit calling a finalizer ?
long after my code is done. I'm wanting to know if I can force it to happen immediately (when the object goes out of scope)
Making an explicit call ? Or an implicit call ? And what about the
reference in the other thread ?
without going back and adding all of the required Dispose() calls..
public Method()
{
CustomClass o = new CustomClass(..);
..
..
..
};
Is there a way to "force" the CustomClass destructor to be called right when the object goes out of scope, by the same thread as the Method?
Dispose is for unmanaged resources.
Garbage collection is for managed resources.
If the object only holds managed resources then let the GC do
what it wants to do when it want to do it.
If the object holds unmanaged resources then use the
Dispose pattern.
Arne
.
- Follow-Ups:
- Re: "forcing" garbage collection
- From: Michael D. Ober
- Re: "forcing" garbage collection
- References:
- "forcing" garbage collection
- From: Jon Mcleod
- "forcing" garbage collection
- Prev by Date: Re: "forcing" garbage collection
- Next by Date: Re: Inheritable Static methods
- Previous by thread: Re: "forcing" garbage collection
- Next by thread: Re: "forcing" garbage collection
- Index(es):