Skip to content

Modify Rule S1215: Add reference to GC.GetTotalMemory #5094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rules/S1215/csharp/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ static void Main(string[] args)

There may be exceptions to this rule: for example, you've just triggered some event that is unique in the run of your program that caused a lot of long-lived objects to die, and you want to release their memory.

This rule also raises on `GC.GetTotalMemory` when `forceFullCollection` is true as it directly invokes `GC.Collect`.

== Resources

=== Documentation

* https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/[Garbage collection]
* https://learn.microsoft.com/en-us/dotnet/api/system.gc.collect[GC.Collect]
* https://learn.microsoft.com/en-us/dotnet/api/system.gc.gettotalmemory[GC.GetTotalMemory]
* https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/latency[Garbage collection latency modes]
* https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/performance#troubleshoot-performance-issues[Garbage collection troubleshoot performance issues]

Expand Down