Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Can I set a memory limit for the .NET Core garbage collector to collect objects more aggressively?

Parent

Can I set a memory limit for the .NET Core garbage collector to collect objects more aggressively?

+6
−0

I have an ASP.NET Core 5 web application that provides functionality that involves file upload + rather large processing (memory consumption mainly). After each processing (with success or not) the memory could be reclaimed.

I have a stress test the endpoint with large files and checked the w3wp.exe process Memory (it runs in IIS) which goes something like this:

  • step 1: 400M
  • step 2: 800M
  • step 3: 1200M
  • step 4: 1800M
  • step 5: 1300M

So there seems to be no memory leak, but GC kicks in very late. I would like for it to begin the cleanup faster, but I cannot seem to find a way to do this. What I have found/tried:

  • why the delay in collection? - objects larger than 85KB are considered large by the GC and will be collected less frequent than smaller objects
  • forcing the GC collection after each operation - this can be done using GC.Collect(), but it is not recommended to do so
  • Runtime configuration options for garbage collection - I have checked GC settings and applied a limit for System.GC.HeapHardLimit, the final configuration looking like this:
{
  "runtimeOptions": {
    "tfm": "net5.0",
    "framework": {
      "name": "Microsoft.AspNetCore.App",
      "version": "5.0.0"
    },
    "runtimeOptions": {
      "configProperties": {
        "System.GC.HeapHardLimit": 1000000000
      }
    },
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

The memory still goes beyond 1GB and stays like this until I process more data and it is finally reclaimed.

  • IIS application pool memory limit - setting the memory limit on the application pool will cause it to be recycled, not forcing the GC to act faster

The application runs on an internal shared server and I would like to have a reasonable peak memory for it.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Why is that a problem? (4 comments)
Post
+1
−0
  • forcing the GC collection after each operation - this can be done using GC.Collect(), but it is not recommended to do so

...unless you have good reason. Here you have good reason.

The other, even more, extreme options would be things like doing the processing in a new AppDomain or spawning a new process to do the processing.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

.NET Core does not support AppDomain unloading (1 comment)
.NET Core does not support AppDomain unloading
meriton‭ wrote almost 3 years ago

On .NET Core, the AppDomain implementation is limited by design and does not provide isolation, unloading, or security boundaries