Sheen Space

Posts Tagged ‘Garbage Collection

Question about .NET GC

leave a comment »

A question at StackOverflow site:

I have had similar question about GC and raised it in this thread:

quoted below:

Here is another great article about GC may occur at unexpected point of code execution:

Lifetime, GC.KeepAlive, handle recycling – by cbrumme

My question is how can I reproduce forced GC at the point mentioned in the article? I tried to put GC.Collect() at beginning of OperateOnHandle(), and defined destructor for class C but seems not working. Destructor is invoked always at end of program.

After others’ help now I can reproduce this behavior. Refer to the question I raised above for update and code I put there. The article written by cbrumme is based on .NET 1.0 and Microsoft has provided elegant solution from .NET 2.0 onwards, that is SafeHandle. Excuse my ignorance.

Written by Ying

19/09/2010 at 11:31