✅ Growing memory issues for ASP.NET Core App
I'm using JetBrians Rider's memory profiler. I found that my application memory growing significantly. The app pretty much pulls stock market's candlestick data, cache it via
MemoryCache
with SlidingExpiration of 10 minute and AbsoluteExpiration of 1 hour. That's pretty much where I think most of the memory goes to.
From the profiling image below, I found that the heap generation is taking lots of space. I searched onlline and found that I should call GC.Collect()
to retain memory. But this stackoverflow post says otherwise.
What can I do to improve the memory usage of my application? What kind of things do I need to look for in order to make it consume less memory?Stack Overflow
What's so wrong about using GC.Collect()?
Although I do understand the serious implications of playing with this function (or at least that's what I think), I fail to see why it's becoming one of these things that respectable programmers w...
20 Replies
use the view that shows you which objects are allocated
it's correct that you generally don't want to call GC.Collect(), the GC runs automatically and if you have a memory leak calling that won't fix it anyway
the most likely issue is that you're holding references to objects you aren't actually using anymore and preventing them from being collected
What's the name of this view?
I can't find that menu :/
you may have to use dotmemory proper and not the rider integration
But anyway, how do I know that I hold references to these objects?
if the GC isn't collecting them then they're being referenced somewhere
So assuming that, it means it's not something from MemoryCache being too large?
it could, depending on how you're using it
the profiler types view will give you some clues, or you could experiment and see what changes reduce the overall memory usage
I still can't find the profiler types view, maybe that's only on Windows. I'm on Linux.
ah yeah, dotmemory is windows only
It's available on Linux as beta though
But I just can't find the types view
the section above the one i linked on the page might help
you need to take a snapshot
or 2, not sure if it works with just 1
Ah found it!
This is the types view, how do I read this?
I don't knokw what's
EventMarker
class is (on the top of the type)googling it suggests it's part of a debug tracing thing
which means it might just go away if you run your project in release mode
Best documentation out there: https://learn.microsoft.com/en-us/dotnet/core/diagnostics/debug-memory-leak
Debug a memory leak tutorial - .NET
Learn how to debug a memory leak in .NET.
Yeah, my memory turns normal once I disabled Sentry's Profiling lol
Thanks for the help @jIMMACLE