Understanding .NET Garbage Collection: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
K
K
Zeile 1: Zeile 1:
 
Every program needs memory. Unfortunately, memory is finite.
 
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.
+
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. <br>
  
[[Datei:NET GC01.png|frame|Figure 1]]
+
[[Datei:NET GC01.png|frame|Figure 1]]<br>
  
 
+
[[Datei:NET GC02.png|800px|frame|Figure 2]]<br>
[[Datei:NET GC02.png|800px|frame|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.
 
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.

Version vom 5. März 2018, 12:44 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





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