Skip to content

Am I getting dumped?

April 6, 2007

How does your object get notified that it is about to be garbage collected?

In .Net world you override the System.Object base class’ Finalize() method. This method is automatically called by the runtime when your object is no longer accessible. This is a good time to release any unmanaged resources that were allocated by your object. The Finalize() method is very special and there are several restrictions governing its use. See resources for details.

If you’re coding in C#, you can’t override System.Object’s Finalize() method. Instead you need to provide a destructor, which in the MSIL is actually a Finalize() override that knows to call the base Finalize().

References:
MSDN: Object.Finalize Method

Advertisements

From → .Net, C#

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: