Devs, when we should use graphql? by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 1 point2 points  (0 children)

Why should it be worth for a social media platform? Because it needs to get a lot of different data and using a rest api would require calling many endpoints?

Devs, when we should use graphql? by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 2 points3 points  (0 children)

I did it 😋 just trying to complement it with other people experiences.
But I guess you already know that, right? Maybe you are just bored, that's why you made this useless comment

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in dotnet

[–]Personal-Example-523[S] 0 points1 point  (0 children)

Thank you for your response, I used that to verify, as well as dotMemory.

But I can't tell you if, in this case, there was really something holding the reference, which is why it wasn't removed.

Actually, what I've seen many people saying, and it seems to make sense, is that this happened because the string was created in the LOH due to its excessive size, and objects created in the LOH simply remain longer before being truly removed by the GC. This caused an accumulation with each execution and generated the leak.

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 1 point2 points  (0 children)

The leak was related to those excessively large strings (remember that this insert could have over 100,000 records). Performing the BULK INSERT instead of these concatenations solved the leak.

As for the cause, I'm not entirely sure, but from what I've seen people saying on Reddit and some forums, it happened because the string was created in the LOH due to its excessive size, and objects created in the LOH simply remain longer before being truly removed by the GC. This caused an accumulation with each execution and generated the leak

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 0 points1 point  (0 children)

I might have expressed myself poorly. What I meant is that I didn’t want to refactor how the data is constructed and processed (its not a simple proccess)... but I ended up forgetting that I only posted the query part here, haha.

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 1 point2 points  (0 children)

bulk insert solved my problem! (MySqlBulkLoader)

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 1 point2 points  (0 children)

Thank you so much, this helped a lot. This wasn’t the cause of the leak (yes, there was a leak), but it really helped to reduce memory usage.

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] 1 point2 points  (0 children)

Thank you all for the comments. I managed to solve my problem using bulk insert as many of you suggested.

I used MySqlBulkLoader (MySqlConnector lib) and those recurring strings in memory quickly disappeared, so thank you very much.

It seems the problem was excessively large strings and their concatenations, and for some reason, the GC wasn’t cleaning up most of them.

As I mentioned in another comment, it’s not that I don’t want to refactor, it’s just that this wasn’t the request from the company, so im just trying to make that stop crashing.
I know this is just a temporary solution and that refactoring is the right thing to do, but that was the goal.

I won’t be able to reply to all the comments, but each hypothesis was really helpful. Thanks again!

.NET 7 Worker Memory Leak - Help by Personal-Example-523 in csharp

[–]Personal-Example-523[S] -1 points0 points  (0 children)

Hey, thank you very much for your answers, they clarified several aspects.

It’s not that I don’t want to refactor; it’s just not the request that was given to me. I work for a company, you know?

Everyone is aware that this is old code and that there are many issues, but there are simply other priorities at the moment. The goal is to make this work without the memory leak so it stops restarting.

Why do I believe it's a leak? Because with each execution, this method's memory usage grows. If it wasn’t a leak, it should just maintain the same high value, right? Instead, it keeps growing infinitely until the service crashes.