Replies: 4 comments 12 replies
-
Hi, I downloaded and ran your test project on my Windows 10 (fully patched) machine, compiled with VS2022 latest. I swapped images, maximized, resized, etc. Weird! |
Beta Was this translation helpful? Give feedback.
-
Avalonia keeps bitmaps uncompressed in memory. There has been discussion in the past about this: In addition, I did my own testing awhile back and found resizing bitmaps on the fly results in very high memory usage: |
Beta Was this translation helpful? Give feedback.
-
Skia is caching bitmap data. The cache is filled up to its limit. The cache is only perged when it hits the limit. Just because you are no longer referencing the bitmap doesn't mean anyone else is holding a reference. Bitmaps are ref counted. On top of all of this comes the fact that SkiaSharp isn't adding any memory pressure for the native bitmap data. So GC isn't cleaning everything up in time. |
Beta Was this translation helpful? Give feedback.
-
Let's continue this thread please
I don't know if Skia3 can be helpful here? I think there is somewhere a thread about how to test it with Avalonia. Off-Topic: Nice App, cool to see you want to port it to Avalonia ❤️ . |
Beta Was this translation helpful? Give feedback.
-
Hi, I created a simple custom control called
DrawingPanel
contains aWriteableBitmap _bmp
and encountered a memory leak issue with Avalonia v11.2.5This is the full source code and test image files: Test_Memory_Leak.zip
contains 2 image files:
512.png
- 512 x 512 px12k.jpg
- 12000 x 12000 pxThe
DrawingPanel
contorl:Here are steps to reproduce:
1. Open
512.png
file => memory is about 122MB2. Open
12k.jpg
file => memory is about 1.8 GB3. Maximize the window and restore it to original size => memory is about 2.3 GB
4. Open
512.png
file again => memory remains 1.2 GB forever!5. If I repeat these steps, memory will keep increasing.
What should I do to resolve this memory leak?
Thanks for help!
Edit: Added videos
After some tests, I notice when I comment out the
c.DrawImage()
function, the issue does not happen.// c.DrawImage(_bmp, new Avalonia.Rect(_bmp.Size), TopLevel.GetTopLevel(this).Bounds);
So I suspect the bitmap data was copied to GPU and still alive when the reference
WriteableBitmap
is disposed.Memory leak with
.DrawBitmap()
memory_leak_drawBitmap.mp4
No memory leak after commenting out the
.DrawBitmap()
no_memory_leak.mp4
Beta Was this translation helpful? Give feedback.
All reactions