A
Armin Zingler
Am 04.08.2010 15:13, schrieb Armin Zingler:
I wanted to keep it simple, but I must correct this!
In the clean-up method, we must distinguish between deterministic
and non-deterministic clean-up. The former is done by explicitly calling
the Dispose method from code. The latter is done by a call from the Finalize
method.
That means:
- In a deterministic clean-up, the unmanaged ressources must
be freed *and* references to managed ressources (for example, large arrays)
can be removed. I write "can", but in a Dispose method it's assumable that
the object won't be used anymore, so replace "can" by "should".
Of course, before removing these references, their Dispose method should
be called also if the object is the owner of the objects, so we have a
cascade-like clean-up.
- In a non-deterministic clean-up, only unmanaged ressources can be freed.
Managed ressources *must not* be accessed because they might have already been
destroyed by the GC.
What I wanted to say with my (now corrected) sentence was that the GC
has nothing to do with the IDisposable pattern.
At the end, I once more point out to the fact that IDisposable is about
*determinstic* clean-up of *unmanaged* ressources and there is zero relation
to the *non-deterministic* work of the GC.
I wanted to keep it simple, but I must correct this!
In the clean-up method, we must distinguish between deterministic
and non-deterministic clean-up. The former is done by explicitly calling
the Dispose method from code. The latter is done by a call from the Finalize
method.
That means:
- In a deterministic clean-up, the unmanaged ressources must
be freed *and* references to managed ressources (for example, large arrays)
can be removed. I write "can", but in a Dispose method it's assumable that
the object won't be used anymore, so replace "can" by "should".
Of course, before removing these references, their Dispose method should
be called also if the object is the owner of the objects, so we have a
cascade-like clean-up.
- In a non-deterministic clean-up, only unmanaged ressources can be freed.
Managed ressources *must not* be accessed because they might have already been
destroyed by the GC.
What I wanted to say with my (now corrected) sentence was that the GC
has nothing to do with the IDisposable pattern.