C
C#8mo ago
kocha

Application memory keeps increasing

I have an application whose memory usage keeps increasing. The obvious thought is that I have a memory leak. But it turns out, that if i force GC via GC.Collect(), the memory usage is stable. So I'm not use what to do now? Should I just regularly call GC.Collect()? But this seems a bit off, and I haven't seen another application needing to do this.
15 Replies
qqdev
qqdev8mo ago
Regularly calling GC.Collect() is often times a red flag Do know which code is causing the increase in memory?
kocha
kochaOP8mo ago
My whole Application, it has a main loop which executes every 16ms and that allocates a bit of memory. But this memory should obviously be freed again.
qqdev
qqdev8mo ago
Can you share what the loop is doing? What is it allocating memory for?
kocha
kochaOP8mo ago
Well, it's the enire UI loop, it renderes a frame 60 times a second.
qqdev
qqdev8mo ago
Are you sure the allocated memory for the frame is managed correctly?
kocha
kochaOP8mo ago
what do you mean by "managed correctly", I know that there are no references for this memory that are kept beyond the current frame, because when I run the GC, it gets freed. When I run dotmemory i see what objects are allocated each frame, and it seems fine.
qqdev
qqdev8mo ago
Like freed or reused by the next frame. Hard to tell what's wrong without actual code at this point
kocha
kochaOP8mo ago
https://github.com/FlurinBruehwiler/flamui This is the code, to test i run the Sample.ComponentGallery sample
GitHub
GitHub - FlurinBruehwiler/flamui: A desktop UI framework
A desktop UI framework. Contribute to FlurinBruehwiler/flamui development by creating an account on GitHub.
kocha
kochaOP8mo ago
it's not a tiny codebase, so not sure how usefull this is maybe i can try creating a minimal repro
qqdev
qqdev8mo ago
Oh yeah true. It's based on SDL, that's good to know You can probably figure out what's wrong by commenting stuff out Since this is an immediate mode UI
//todo wtf is happening grrrr it makes 0 sense
:when:
kocha
kochaOP8mo ago
hahha
kocha
kochaOP8mo ago
yeah, i can try, but do you have any idea what "concept" could be causing this behaviour, like I don't really understand when the GC decided to collect. MS just lists these points:
No description
kocha
kochaOP8mo ago
is the memory not hitting a "threshold", and therefor the GC doesn't run?
qqdev
qqdev8mo ago
The increasing memory makes it seem that it is an actual memory leak You can check if the GC is doing stuff by using a profiler for example I think VS is also displaying when the GC kicks in (while debugging) But: Because GC.Collect() helps -> It might not kick in often enough for that 60fps. Using a profiler will tell you everything you need to know
reflectronic
reflectronic8mo ago
it's not a memory leak if GC.Collect() fixes the issue. the GC is just not running because it decides that it has no reason to run it will run later
Want results from more Discord servers?
Add your server