@okarlsson commented on Thu Apr 05 2018
Hey Guys!
I'm running a .NET Core application in a docker container that runs in a EC2 instance on AWS.
I have a function for resizing profile images before they get uploaded and I'm using a third party library called ImageSharp for this. The library uses ArrayPools when handling the images and my memory usage shoots up to about 1GB after handling a image.
But after the request has completed the memory usage never goes back, but is allocated to these memory pools.

Since I only have 1GB memory in my EC2 instance the entire instance crashes if I try to for example deploy a new version of my app when there is only 70MB memory available.
Is there any way to free up the memory allocated to the ArrayPools after I have finished a request so my containers don't run out of memory?
@jkotas @maoni0 Related to dotnet/runtime#9737, etc.?
Assuming Future.
@okarlsson I mentioned this to @JimBobSquarePants and he mentioned there is a article about memory use for ImageSharp; it also has fine grained control over its pooling with the ArrayPoolMemoryManager; including clearing the pools with ReleaseRetainedResources(), using smaller pools with CreateWithModeratePooling() and CreateWithMinimalPooling() or full control via the ArrayPoolMemoryManager constructor.
HTH
Awesome, thanks for the tip @benaadams
@okarlsson also make sure to use the latest (beta-3) version of ImageSharp!
Based on your stack trace, you are using an earlier version, where the memory management is immature and sub-optimal!
Will do @antonfirsov , thanks!
Most helpful comment
@okarlsson I mentioned this to @JimBobSquarePants and he mentioned there is a article about memory use for ImageSharp; it also has fine grained control over its pooling with the
ArrayPoolMemoryManager; including clearing the pools withReleaseRetainedResources(), using smaller pools withCreateWithModeratePooling()andCreateWithMinimalPooling()or full control via theArrayPoolMemoryManagerconstructor.HTH