AnointedAutomation.Memory 1.0.6

dotnet add package AnointedAutomation.Memory --version 1.0.6
                    
NuGet\Install-Package AnointedAutomation.Memory -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AnointedAutomation.Memory" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AnointedAutomation.Memory" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="AnointedAutomation.Memory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AnointedAutomation.Memory --version 1.0.6
                    
#r "nuget: AnointedAutomation.Memory, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AnointedAutomation.Memory@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AnointedAutomation.Memory&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=AnointedAutomation.Memory&version=1.0.6
                    
Install as a Cake Tool

AnointedAutomation.Memory

Jesus is King ✝️

A small .NET utility for on-demand garbage collection. It forces a full collection, waits for finalizers, and then tries to hand unused memory back to the operating system, which is useful for long running services after a memory heavy job.

NuGet Downloads

Installation

dotnet add package AnointedAutomation.Memory
  • Target framework: net10.0
  • Dependencies: none

Note that the namespace is AnointedAutomation.Optimization.Memory, not the package id.

Quick start

using AnointedAutomation.Optimization.Memory;

GarbageCollection gc = new GarbageCollection();

// After a large import, export, or batch job:
gc.PerformGarbageCollection(null);

API overview

Namespace: AnointedAutomation.Optimization.Memory

Member Description
GarbageCollection() Creates an instance. The class holds no state.
void PerformGarbageCollection(object state) Runs GC.Collect(), then GC.WaitForPendingFinalizers(), then attempts to return unused memory to the OS. state is unused.

How the memory return works:

  1. Reads the current managed heap size with GC.GetTotalMemory(false).
  2. If it is greater than zero, calls GC.TryStartNoGCRegion with that size.
  3. If the region starts, immediately calls GC.EndNoGCRegion().
  4. An InvalidOperationException from this step is swallowed, so the call never fails on it.

Running on a timer

PerformGarbageCollection takes an object state parameter so it matches the TimerCallback delegate and can be scheduled directly:

using System;
using System.Threading;
using AnointedAutomation.Optimization.Memory;

GarbageCollection gc = new GarbageCollection();
Timer timer = new Timer(gc.PerformGarbageCollection, null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(30));

Keep a reference to the Timer for as long as it should run.

Best practices

  • Use sparingly. A forced full collection pauses the application and usually is not needed; the .NET GC tunes itself well.
  • Best suited to the moment right after a large, short lived allocation spike.
  • Measure before and after (for example with GC.GetTotalMemory or dotnet-counters) to confirm it helps your workload.

License

MIT. See LICENSE. Copyright © Anointed Automation, LLC. Stewarded by Alexander Fields.

Support This Project

This library is free and open source. The best way to support the work is to shop with us:

Found a bug or have a request? Open an issue: https://github.com/AnointedAutomation/AnointedAutomation/issues

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AnointedAutomation.Memory:

Package Downloads
AnointedAutomation.APIMiddlewares

ASP.NET Core middleware and filters for API key authentication, IP blacklisting, invalid endpoint tracking and idle time memory cleanup.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 190 10/1/2026
1.0.5 120 10/1/2026
1.0.4 225 9/25/2026
1.0.3 422 8/23/2026
1.0.2 772 6/20/2026
1.0.1 319 5/30/2026
1.0.0 642 3/15/2026
0.0.6 257 3/11/2026
0.0.5 618 2/17/2026