Memory Management in .NET

(1) source article from MSDN : Garbage Collector Basics and Performance Hints

Conclusion

“The .NET garbage collector provides a high-speed allocation service with good use of memory and no long-term fragmentation problems, however it is possible to do things that will give you much less than optimal performance.

To get the best out of the allocator you should consider practices such as the following:

  • Allocate all of the memory (or as much as possible) to be used with a given data structure at the same time.
  • Remove temporary allocations that can be avoided with little penalty in complexity.
  • Minimize the number of times object pointers get written, especially those writes made to older objects.
  • Reduce the density of pointers in your data structures.
  • Make limited use of finalizers, and then only on “leaf” objects, as much as possible. Break objects if necessary to help with this.”

(2) source article : Memory Management Misconceptions

1. A garbage collector collects garbage
2. Doing lots of gen0 collections is bad
3. Performance counters are great for understanding what is happening
4. .NET doesn’t leak memory
5. All objects are treated the same

I believe they are highly recommended well-written articles. Enjoy! 🙂

Advertisements

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