Silverlight: How to unload (delete) an image from memory?

I have an image control that displays a large jpg file and takes up about 50 MB of memory. How to get rid of this control when it is no longer needed? I tried removing it from the parent container by setting it to null and changing its Source property to null, but the memory usage still remains unchanged ... Any suggestions would be much appreciated!

+6
c # silverlight
source share
2 answers

I finally found the answer to my question. The problem was a memory leak error in Silverlight. I found a workaround for this problem: http://blogs.msdn.com/silverlight_sdk/pages/silverlight-bugs-and-workarounds.aspx

Memory leak when dynamically adding and deleting Images

Workaround: When dynamically adding or removing BitmapImages from the application (aka add / remove from the tree), you must set Image.Source = null before deleting the Image element from the tree. This will make BitmapImage acceptable for garbage collection. Error: Asset Error. *

Thanks everyone for the suggestions!

+9
source share

I think this is a marginal case issue with Silverlight due to garbage collection dependency. Unfortunately, if you create a lot of objects (and I mean a lot), you will get a performance boost (even if you release everything correctly and / or Dispose () everything), because the GC just does not have time and we do not have resources that You can quit, as in a regular application.

Having a problem or just looking at the memory?

0
source share

All Articles