I’m currently running a .NET-based API inside a Docker container. During stress testing, I’ve observed that the container’s memory usage keeps increasing steadily when the API is hit continuously with requests — especially those that are resource-heavy (e.g., file decompression, zipping, memory-stream operations, etc.).
Despite:
Applying proper disposal patterns (using, Dispose, null)
Forcing GC.Collect() in finally blocks
Enabling GC tuning with these settings:
environment:
- DOTNET_GCHeapHardLimitPercent=75
- DOTNET_GCTrimCommitOnLowMemory=1
- MALLOC_TRIM_THRESHOLD_=131072
- DOTNET_GCHeapAffinitizeMask=0x3
- DOTNET_DefaultStackSize=180000
Periodically clearing cache in cronjobs
Validating that no temp file or log buildup is occurring (du -sh)
The container still keeps increasing memory usage until it crashes or gets OOM-killed. No memory is released back to the OS.