The blog has moved to a new address. The blog is now located at http://devintelligence.com

Adsense

Sunday, September 03, 2006

Memory Management

Automatic memory management is one of the services during Managed Execution that makes a developer's life a bit easier. Developers do not have to worry about freeing objects when they are no longer used, since the garbage collector takes care of that. The garbage collector determines which objects have no references and can therefore be released from memory. This prevents many problems such as forgetting to free objects from memory, causing memory leaks or attempting to access memory that has already been released.
The problem with automatic memory management
The automatic memory management technique is not perfect. As explained above, an object can be collected by the garbage collector when the object has no more references. It's logical that a button will not be collected when a form still knows it's there, but there are other references that a programmer might not expect, that also keep an object alive.
An eventhandler can be such a reference that it will prevent the object from being collected. Another example is using a static collection object to register certain object instances. These instances will never be collected since the collection always has a reference to them. An IMessageFilter to handle window messages also has the same collection problem.
The solution
To prevent this kind of problems,
qios has created a system that uses WeakReferences to attach to events, collection members, and IMessageFilters. A WeakReference is a reference to an object that will allow it to be garbage collected.

To read more about our solution to these problems, check out a free and open source sample and libary available for download.You are allowed to use the MemoryPack library in your own applications without any costs.

1 comment:

Anonymous said...

Hi,

Here is a detailed article on dot net garbage collector and memory management.

http://dotnetinternal.blogspot.comEnjoy :)