Closed BobLd closed 1 year ago
Does it grow indefinitely or stops at some point?
@kekekeks It grows to roughly 250MB and stays there. Loading/Unloading does not increases unmanaged memory beyond this point. From what I see, it then stays at this level and never decreases.
After some time unloaded, I would expect unmanaged memory to go back to baseline level which does not seem to happen
You are saturating Skia's cache. You can try reducing said cache size.
@kekekeks okay I did not know about that, thx a lot.
I understand now it's more a skiasharp question than an Avalonia one, but could I ask how you would reduce the skia cache in an Avalonia context?
I've added the possibility to manually purge Skia's (non-gpu related) cache by doing SKGraphics.PurgeAllCaches();
(see doc here) and also added lease.GrContext.PurgeResources();
in the ICustomDrawOperation
.
Doing so I managed to only reach ~210MB instead of the 250MB plateau, but the memory still increase as seen on the screenshot.
If anyone has an idea how to purge more of the skia cache, let me know
Are you running with integrated GPU? That might be memory pre-allocated by the driver.
@BobLd I honestly don't see a real memory leak here where memory increases infinite. For me it is more a question how to reduce memory in general. Correct me if I'm wrong.
I did 2 other tests:
Deactivating the GPU rendering by setting (let me know if this is not the way to do that)
.With(new Win32PlatformOptions
{
RenderingMode = new[]
{
Win32RenderingMode.Software // No GPU acceleration
}
})
and the memory profile is closer to what I would expect: unmanaged memory goes down to baseline level when unloading (on top of using way less of it):
Then to @kekekeks point about integrated GPU, these examples were indeed running on integrated GPU (AMD Radeon(TM) Graphics). Forcing the app to run on my NVIDIA GeForce RTX 2060, the memory profile seems to indeed behave better by looking at the Task Manager: Memory is at 175MB when skpicture loaded, and goes down to 50MB when unloaded and so even after several load/unload (I'm unable to run the app through dotMemory with this GPU though).
@timunie I don't think this is necessary a memory leak, I'm just puzzled as to why memory in not released when unloading the skPicture, and grows up to a certain level and stays there... Even more now that running this app on the GeForce card does not displays the same behaviour...
Not sure what to conclude, the behaviour seems to be limited to integrated GPU, and I don't know why it happens. Might indeed be 'pre-allocated memory', I was unaware of that - will look into it. (by the way, is there a way to force Avalonia to use one GPU in particular from the app itself, i.e. for it to use GPU 0 instead of GPU 1?).
Feel free to close this issue if you think this is in fact not an issue
I somehow feel like this is either an issue with the graphic card or with skia sharp, as we don't manage SKPicture. So probably you can ask SkiaSharp for help.
worth to notice that we have a PR open to test newer Skia-version here: #12729 You may want to try it out if it helps in your situation.
For now, I'll move this issue into a general discussion as I think the input is valueable for others, but not an Avalonia issue.
Describe the bug There's a possible memory issue when drawing
SKPicture
directly on the canvas. After disposing of theSKPicture
, it seems some (unmanaged) memory is not released.Subsequent Loading/Unloading of the picture lead to growing unmanaged memory. This memory is never released it seems.
I'm using the control from https://github.com/wieslawsoltes/Svg.Skia to draw the
SKPicture
To Reproduce Please find a minimal app to reproduce the issue here https://github.com/BobLd/IssueCanvas
Steps to reproduce the behavior:
Expected behavior I would expect unmanaged memory to not grow over subsequent Load/Unload, and to be restored to baseline level.
Screenshots The screenshot below shows memory usage in dotMemory and the subsequent Load/Unload. As an FYI, the baseline (app started, but Load button never clicked) Unmanaged memory usage is around 70MB on my computer. We can see here that we end up at 250MB and stay there:
Desktop (please complete the following information):
Additional context I'm drawing the picture that can be found here and you can use https://chrome-m93-debugger.skia.org/ to look into it