Fix Avalonia SvgImage reload resource leak#512
Merged
Conversation
This was referenced May 12, 2026
This was referenced May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary: Fix SvgImage Reload Resource Leak
Related Issue
Fixes #433.
Problem
The Avalonia
SvgImagecontrol could repeatedly reload the same SVG source when style-related properties changed, even when the effective CSS value had not changed. In the issue repro, the SVG image was placed inside aButton; repeated interaction caused inherited style notifications and reloads of the same icon.Those reloads replaced the
SvgSource'sSKSvg,SKPicture, and cached original stream without disposing the previously held native resources. Over time this retained native Skia resources and showed up as memory growth in the Avalonia button scenario.Changes
Dispose replaced SvgSource resources
ReplaceResourcespath inSvgSource.SKPicture,SKSvg, and cached stream resources are disposed whenever a load or reload replaces them.Avoid redundant SvgImage CSS reloads
ReLoadSourcehelper.SvgSource.Cssproperty.SvgSource.CssandSvgSource.Entitieswhen a source has not loaded yet.Regression tests
SvgImagedoes not reload when the effective CSS is unchanged.Commit Split
f6530baa4 Dispose replaced Avalonia SVG resourcessrc/Svg.Controls.Skia.Avalonia/SvgSource.cstests/Svg.Controls.Skia.Avalonia.UnitTests/SvgSourceTests.cs7f2f38a8f Avoid redundant SvgImage CSS reloadssrc/Svg.Controls.Skia.Avalonia/SvgImage.cstests/Svg.Controls.Skia.Avalonia.UnitTests/SvgImageTests.csValidation
The following checks were run successfully:
Focused Avalonia controls tests passed with 15 tests. The full solution test pass completed successfully. The build still reports existing package vulnerability warnings, but no build errors or test failures.
Risk Notes
BeginRenderandEndRendersynchronization model and only changes when replaced native resources are released.SvgParameters.Cssare handled correctly.