Runtime: Freeing up memory from ArrayPools

Created on 5 Apr 2018  路  7Comments  路  Source: dotnet/runtime

@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.

image

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?

area-GC-coreclr tenet-performance

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 with ReleaseRetainedResources(), using smaller pools with CreateWithModeratePooling() and CreateWithMinimalPooling() or full control via the ArrayPoolMemoryManager constructor.

HTH

All 7 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fiigii picture fiigii  路  181Comments

terrajobst picture terrajobst  路  158Comments

jamesqo picture jamesqo  路  182Comments

iSazonov picture iSazonov  路  139Comments

hqueue picture hqueue  路  155Comments