C#C
C#15mo ago
Kiel

Questions/concerns about memory usage in my project

Apologies for the messy formatting, I created this post because of multiple concerns and/or observations while profiling it. The first part is that I'm not very familiar with how GC works or is expected to work. Clearly in the first screenshot the drops are caused by garbage collection, but I'm unsure what's causing the gradual rises in memory. Is this just normal behavior since it seems to always drop to around the same level each time GC runs?

Second question: What could cause total memory usage to vary wildly over the duration of a project running? In my case, this is a Discord bot profiled by dotMemory over the course of >24 hours (second screenshot). It reached a peak of 4.91GB used, and now we're currently using 2GB and the lowest total memory used was about 1.3GB. Snapshots have not shown me anything extremely out of the ordinary, it's expected data to be in memory. The only confusing part is that there are large quantities of CancellationTokenSources (third screenshot), despite every instance of one wrapped within a using statement to ensure it was disposed of.

I'm very new to disgnosing memory leaks and/or usage issues so if I'm expressing incorrect assumptions or missing anything extremely obvious, let me know. I can post screenshots of my snapshots or anything else that might be relevant if needed.
image.png
image.png
image.png
Was this page helpful?