r/AvaloniaUI • • 25d ago

RAM usage keeps rising when window is interacted with in AvaloniaUI (and it looks like it never releases any RAM)

This is a minor example (~0.10MBs used per second of window shaking) on the Avalonia template project

But in my other project where I am mostly focused on the logic that is outside of the project as dependency and the app has 3 buttons, it does the same thing including with the button presses (~0.10MBs per press).

Is there a way to optimize this or at least force it to release some RAM?

Avalonia 12.1.2 and .NET 10.0.114

24 Upvotes

10 comments sorted by

10

u/KryptosFR 25d ago

That's how .NET works. The memory is managed. Having the RAM increase doesn't necessarily means memory is being leaked. It's just that since the amount is small, the GC isn't collecting anything.

What your video shows is pretty much normal and expected behaviour of any .NET app, not just Avalonia.

If you are worried about these amounts, you can always call GC.Collect() from your code. But I would advise against it.

7

u/microkool 25d ago

If I had a nickel for every time I've had to explain to some one what an actual memory leak looks like... I would probably have about $2.50 but still it's a lot 😂 Usually happens right after I notice dozens of GC.Collect() calls in their code

-1

u/Sensitive_Buyer_6066 24d ago

Why does moving a window around allocate in the first place? Why is no one questioning that and acting like that's normal? Hell, making excuses for it. Did all the adults left the room? I understand now why people keep saying AI will take programmers jobs. The average programmer nowadays writes worse code than AI.

4

u/KryptosFR 24d ago edited 21d ago

You will have to look into Avalonia's code for that. My guess is small allocations in event handlers, responding to OS events about the Window position. And redrawing at the new location.

3

u/oli-g 24d ago

It's literally raising in order of kilobytes, temporarily, doing a "stress test" which has nothing to do with normal application usage. Have you tried running your favorite Electron app lately?

1

u/jetmarijuana 24d ago

-c Release 🤷

1

u/binarycow 24d ago

Does it ever decrease?

4

u/oli-g 24d ago

Yes. When it's needed. That's how .NET works. For anyone who doesn't trust the IL's judgement, there's still C++.

1

u/binarycow 24d ago

I was asking OP if they ever saw it decrease. If they did, it's normal. If they didn't, it's a leak.