-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Known issue: WPF Image memory leak when remove image from visual tree #2397
Comments
How to solve it? In order to solve it , you should set the image.Source is null and use UpdateLayout. The below code can solve it.
|
Why the image will memory leak? Because the Image use RenderData class to storage the image source object and the The image will never re-render when we remove the image from the visual tree and the RenderData will never update. Why we set the image source as null and then update layout can solve? Because the image source is null and the update layout will call render to update the |
@lindexi, you are amazing! Thank you so much for providing a solution as well as an explanation! |
Hi @lindexi Thank you for the insights you have provided. However, when I tried to reproduce the issue, it seems the increase in memory is due to the oldBorder element retention at line #38. Please share more information such as memory dump taken at different intervals which shows the memory increase (after commenting out the aforementioned line 38). This will help us repro the issue at our end and will help us narrow down the problem. |
@Kuldeep-MS Thank you.
Right. We must keep the Image control alive, and we should remove the current Image control from the visual tree. The But the In other words, the Image control not being recycled is as expected. But the It means that the And I think we can fix this by #7177 |
Problem description:
The image source will memory leak when we remove the image from visual tree before we set the image source as null
Step:
And you can find the image source object never free
Actual behavior:
The Image memory leak
Expected behavior:
The image source object can be free
Minimal repro:
https://github.com/dotnet-campus/wpf-issues/tree/master/ImageMemoryLeakDotNetCore
The text was updated successfully, but these errors were encountered: