#732 – Destruction vs. Collection

Automatic memory management in C# means that the memory for a heap-based object is automatically released when there is no longer any user-written code that references the object.  This is done by the garbage collector.

An object goes through two distinct phases when it is no longer referenced–destruction and collection.

When an object is no longer referenced by any user-written code, other than code in a destructor, the object becomes eligible for destruction.

Once the object is eligible for destruction, it may be destructed at some point in the future, i.e. its destructor is called.

After the object is destructed and it is no longer being referenced by any code, including code in a destructor, the object becomes eligible for collection.

Once the object is eligible for collection, the garbage collector may at some point in the future release memory for the object.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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: