Disposed List

You use a GarbageCollectedLanguage? and you’re afraid of MemoryLeakUsingGarbageCollection. You need a way to quickly detect memory leaks before their crash your application in production. Therefore, you might want to use a DisposedList.

When you know a reference is pointing to an object that has reached its end of life, register it to the DisposedList. That list will keep the reference through a WeakReference. Regularly, a background thread scans this list and removes the references that are reclaimed. If there are some live references, it also invokes the GarbageCollector. If a reference remains in the list for more than several seconds, that means you have a leak.

The reference registration can be done by a dispose method if you use that pattern.

If your language allows you to do that, the registration method can also store the calling stack to ease further debugging and investigation.

If you use a centralized event mechanism, the disposition registration method could also scan through all the event listener lists to be sure the instance is not listening to anything else. If this is the case, then you have a leak. You can dump that leak to some logging system and do the cleanup to allow memory reclaiming.

Once you use the DisposedList extensively through the entire application, you usually discover how easily leaks can be done with a GarbageCollector.

-- PhilippeDetournay


CategoryGarbageCollection


EditText of this page (last edited September 3, 2006) or FindPage with title or text search