> Allocating an object "on the stack" will not trigger a GC either when
> it goes out-of scope. Provided it has a destructor, Dispose() is
> automatically called when it leaves the scope, but that's it. The
> object will be collected non-deterministically when the GC comes
> along.
I believe that's what I said. Bottom line for the OP: there is no such
thing as marking an object for collection or forcing an object to be
collected. You can force an object to be disposed, which is the technique
of preference for situations where you need deterministic cleanup of
non-memory resources (like DB connections).
-cd
Ronald Laeremans [MSFT] - 29 Jun 2005 06:59 GMT
>>Allocating an object "on the stack" will not trigger a GC either when
>>it goes out-of scope. Provided it has a destructor, Dispose() is
[quoted text clipped - 9 lines]
>
> -cd
Also setting the reference to nullptr for a local does nothing useful
whatsoever. The JIT compiler marks GC lifetime regions, so if after a
certain point in the IL you no longer reference this object, the memory
it uses can be collected from that time on regardless of whether the
local reference still points to it.
Look here for the details:
http://blogs.msdn.com/yunjin/archive/2005/05/15/417569.aspx
Ronald Laeremans
Visual C++ team