Skip to content

Commit

Permalink
Update xml/System/GC.xml
Browse files Browse the repository at this point in the history
Co-authored-by: Genevieve Warren <[email protected]>
  • Loading branch information
Maoni0 and gewarren authored Jan 9, 2025
1 parent e4b29a3 commit 99cf22c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion xml/System/GC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ The following example uses several GC methods to get generation and memory infor
The common pattern for releasing native resources is via a type's finalizer. If a managed object uses native memory, it can free that native memory in its finalizer. The garbage collector only knows about managed memory and schedules collections based on this knowledge. Imagine a scenario where a small managed object is associated with a large amount of native memory usage, and this managed object now lives in gen2. A gen2 GC might not happen for some time, which means the large amount of native memory won't be released until the next gen2 happens. The runtime provides the <xref:System.GC.AddMemoryPressure%2A> and <xref:System.GC.RemoveMemoryPressure%2A> methods to help with this scenario. The runtime keeps an internal record of how much memory pressure these APIs added and removed, and triggers a gen2 GC if deemed productive. So this is not a feature of the GC but rather something that the runtime provides to trigger GCs.
If you have a convenient place to call these APIs, you don't necessarily have to have a finalizer. For example, when a specific method on the type is called you know you can release the native memory, you can call the <xref:System.GC.RemoveMemoryPressure%2A> method at that point instead of having a finalizer.
If you have a convenient place to call these APIs, you don't necessarily have to use a finalizer. For example, if you know you can release the native memory when a specific method on the type is called, you can call the <xref:System.GC.RemoveMemoryPressure%2A> method at that point instead of having a finalizer.
> [!CAUTION]
> You must ensure that you remove exactly the amount of pressure you add. Failing to do so can adversely affect the performance of the system in applications that run for long periods of time.
Expand Down

0 comments on commit 99cf22c

Please sign in to comment.