Sheen Space

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: