Need help with some memory leaks
I got this file of code here.
My code just runs fine over time without it, and when its running it starts producing memory leaks.
I tried for 2-3 days now to fix and can't find it.
It is supposed to check the status of every shard in the database and save it in the database. It always checks a maximum of 5 shards at the same time. I'm coding a discord bot with C# and ASP.NET
When you need more context to fix this kind of problem feel free to dm me please
Thanks
18 Replies
Explanation of my code:
ISimpleLogger is a logger interface and it just simply logs something in the console with time and colors.
var client = _clientFactory.CreateClient("BotHttp");
BotHttp looks like this:
builder.Services.AddHttpClient("BotHttp", (provider, client) =>
{
client.Timeout = TimeSpan.FromSeconds(10);
client.DefaultRequestHeaders.Add("X-API-KEY", provider.GetRequiredService<IOptions<BotConfig>>().Value.BotApiKey);
});
I don't see anything suspicious there either
Are you sure you have a memory leak?
My ram just goes up like a staircase over several hours. I'm not sure
is there any additional cost if you perform more query?
if not then make
ExecuteAsync loop faster so that you can take two heap snapshots within a shorter period (or just wait and compare the objects in heap)Should not. I will try that and tell here
the "cost" i mean is the charge (money) you that need to pay (to cloud etc)
No. It doesnt cost anything
It went up by maybe 5MB in your graph?
Yeah, its always 5-8mb then like an hour it stays the same and then again.
Bear in mind that the GC will expand the memory it uses if it thinks it can be more efficient by doing that, but it will give memory back to the OS if the OS asks for it back
Would it help to send my diagnostic session?
Ah that would make sense. The first one or two hours it takes more and more and then it stays the same for like 6 hours of testing. That would explain it
But is it normal that my Network Usage and I/O is rising? I'm just running this background task, nothing else
aggregate
Lol, of course omg
So you think it is normal and probably not a memory leak? I can watch the usage for a few days
I haven't seen anything which makes me think you definitely have a memory leak
Yeah I'd run it for a few days, or a week even. If it doesn't level off, then I'd start getting suspicious
Ok, then I'll try that. Thanks for your quick help ^^
👍
Take dump file and analyze it. Check which objects cause allocation
Please learn to use memory profilers and that can help determine whether there are memory leaks or not. Dump analysis can yield similar information but not as intuitive.
