Back to basic: Series on dynamic memory management

Beach by the side of Suratkal Engineering college

After becoming the .NET Compact Framework (.NETCF) dynamic memory management module owner I am continually learning a lot about the subject. Based on hallway discussion I figured out that a lot of developers are not very clear about the subject and would like to learn more. Most online material I encountered gets into too much of details and implementation for most casual readers.

So here is my attempt to write up a series on GC. I plan to cover the basic stuff and then move into details of .NET CF GC including performance, profiling. I plan to cover bits of desktop .NET GC as well (but for that Maoni’s blog is a better resource) The first two in this series is already published. I will keep this post updated to act as an index into the series.

  1. Memory allocation, a walk down the history

  2. Why use garbage collection

  3. Reference Counting Garbage Collection

  4. Mark-sweep garbage collection

  5. Copying garbage collection

  6. Optimizing reference counting garbage collection

  7. Handling overflow in mark stage

  8. Generational Garbage Collection

  9. How does the GC find object references

  10. More to come … 🙂

In case you have some suggestion send it my way and I will ty to include that as well…

Comments (4)

  1. Petr Kodet says:

    Hello BonGGeek,

    hopefully you could help me with advice regarding some detailos of GC behaviour. Please let me explain the motivation (the problem background) first :

    For my NET CF application, I would like to implement cache of object used by User Interface; in this particular case cache of bitmaps which are created by loading and my custom-processing of PNG images. In order to avoid implementing everything quite from the scratch (which would include objects referece counting, lifetime management etc.), I would like to use weak refereces as values kept in the cache. In other words, the cache would internally utilize DictionaryEx<string, GCHandle>,  with GCHandle created with type GCHandleType.Weak, analogically like for instance in


    Unfortunatelly, it is quite tricky to use such cache for IDisposable objects, if the cached objects keep significant amount of non-managed data, and have to call finalizer to free such data. If the implementation truly relies just on the behaviour of weak-references lets just GC to free the objects in the time GC finds appropriate, it is qute likely the application sooner or later gets OutOfMemoryException; because of delayed calls of Finalizers.  Please see the details in  Scott Holden’s Blog: Do Bitmaps leak memory?


    Therefore, I desparately searched for a way how to enforce proper IDisposable-derived object disposal, including its un-managed data, at the moment it is collected by GC and its weak reference ( GCHandle ) is zeroed.  I was thinking about either some event I could subscribe to; or about some GC method, but did not find enything of that kind,

    Please let me know if there is way to achieve such effect.

    Thank you

    Petr Kodet

    Telematix Software a.s.

    Na Žertvách 34

    180 00, Prague 8

    Czech Republic

  2. Interessanti articoli sul Garbage Collector di .NET

  3. Nel blog I know the answer (it&#39;s 42) è possibile trovare una serie è possibile trovare una serie