Total Downloads

2,591,097

Total Files

9,206

Latest Update

10

How to (not) use the large object heap in .Net

Posted August 7, 2017 | Windows


When working with .Net, it is important to understand how the garbage collector works. The .Net CLR manages two different heaps, the small object heap (SOH) and the large object heap (LOH). This article will focus on how the runtime manages the large object heap, and why the large object heap is prone to memory fragmentation that can impact the performance of your application. It will also discuss the best practices you can use to keep LOH memory fragmentation to a minimum.

The garbage collector is quite adept at cleaning up resources that are no longer being used by your application. However, the small object heap and the large object heap work differently. Let’s start with the small object heap.

When a small object is created (less than 85KB in size), it is stored in the small object heap. The CLR organizes the small object heap into three generations – generation 0, generation 1, and generation 2 – that are collected at different intervals. Small objects are generally allocated to generation 0, and if they survive a GC cycle, they are promoted to generation 1. If they survive the next GC cycle, they are promoted to generation 2.

Further, garbage collection of the small object heap includes compaction, meaning that as unused objects are collected, the GC moves living objects into the gaps to eliminate fragmentation and make sure that the available memory is contiguous. Of course, compaction involves overhead – both CPU cycles and additional memory for copying objects. Because the benefits of compaction outweigh the costs for small objects, compaction is performed automatically on the small object heap.



Source link

')
ankara escort çankaya escort çankaya escort escort bayan çankaya istanbul rus escort eryaman escort ankara escort kızılay escort istanbul escort ankara escort ankara escort escort ankara istanbul rus Escort atasehir Escort beylikduzu Escort Ankara Escort malatya Escort kuşadası Escort gaziantep Escort izmir Escort