Forum Discussion
SamXion
Nov 12, 2021Copper Contributor
Why is my ASP.Net Web API piling up memory?
Hi everyone, I have a very simple MVC web api with a single controller that currently does nothing but returning a value. I am publishing it in VS2022 Preview 1 into a single file, so I get an .e...
- Nov 14, 2021If you're calling it ever 250ms, it's likely not quiet enough for the Garbage collector to fire up. And with 90mb, it likely isn't pushing enough memory pressure (that's still tiny) to force the Garbage collector.
Codenamejack
Nov 13, 2021Copper Contributor
Have you tried launching it without debugger? Maybe with dotnet run command. Is the behaviour same even then?
shawnwildermuth
Nov 14, 2021Copper Contributor
If you're calling it ever 250ms, it's likely not quiet enough for the Garbage collector to fire up. And with 90mb, it likely isn't pushing enough memory pressure (that's still tiny) to force the Garbage collector.
- SamXionNov 15, 2021Copper ContributorOk, I have to apologize and row back here. Even though I called GC.Collect(), I just noticed that I was running an older build that did NOT call the garbage collection. Running the latest build does indeed get rid of the memory piling.
So thanks for the help! This resolves my issue. 🙂 - SamXionNov 15, 2021Copper Contributor
Thanks. That was also my initial thought, so I was calling GC.Collect() at the end of each request (i.e. before return 0;), simply to force the gc to free all generations but...no change and no memory freed. RAM still piling up. 😕
It seems strange that this does not happen when running the API in debug mode from inside of VS. This gives me the impression that it might not be the API itself maybe? Maybe it's how I spawn the process (doing this from C++ via Qt and QProcess).- SamXionNov 15, 2021Copper ContributorHmm, even if I start the API manually (double-clicking the executable), this memory piling occurs. So it's not due to the process spawning itself either.