Understanding .NET Garbage Collection: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
K
Zeile 16: Zeile 16:
  
  
 +
== Large Objects ==
 +
The Common Language Runtime (CLR) allocates large objects on the Large Object Heap (LOH). The primary difference with the previous algorithm is that the garbage collector never compacts this heap. This increases performance, but there is a catch. There may not be enough room for a new object even with enough available memory. This causes the CLR to throw an inappropriately named OutOfMemoryException.
  
 
+
[[Datei:NET GC03.png|600px|thumb|Figure 3]]
  
  

Version vom 5. März 2018, 14:05 Uhr

Every program needs memory. Unfortunately, memory is finite.

Software must cope with memory usage, and there are two ways to manage it: manually and automatically. Manual memory management is prone to errors, especially with exceptions and asynchronous code. This is why modern managed environments (.NET, Erlang, and many more) implement automatic memory management with garbage collection.

Figure 1

Figure 2

No object or application root in Figure 2 has a reference to Object D or Object H. In the garbage collection process, the garbage collector discards both of these objects then compacts the heap.

There is a potential issue with this scenario. Assuming Object E occupies a large amount of memory, e.g. 300 MB, the performance will be suboptimal when the garbage collector moves Object E to Object D’s memory location.

In .NET objects are divided into two groups:

  • Large Objects – larger than 85KB or multidimensional arrays
  • Small Objects – everything else


Large Objects

The Common Language Runtime (CLR) allocates large objects on the Large Object Heap (LOH). The primary difference with the previous algorithm is that the garbage collector never compacts this heap. This increases performance, but there is a catch. There may not be enough room for a new object even with enough available memory. This causes the CLR to throw an inappropriately named OutOfMemoryException.

Figure 3



Source: https://www.telerik.com/blogs/understanding-net-garbage-collection