Using MemoryPolicy.UnloadUnused to unload unused images

Hi, my application is quite image heavy, and therefore I am dependent on unloading images after they have been used to not run out of memory on mobile platform. As far as I can understand, this should be done using MemoryPolicy.UnloadUnused on the imageelements, but it seems to do nothing. When is it supposed to unload? 60 seconds after the element is unrooted (unpinned) or are there other rules aswell?

60 seconds after being unrooted should be enough for UnloadUnused. This should also unload images which are invisible (any ancestor is invisible). How are you determining that they are not being unloaded? Can you show me a sample of the UX you are using?

I am only checking the ram usage (on ios and for the dotnet executable) and it never goes back down again the images are loaded. Ill try to create a simple testcase to see if it is reproduceable.


Press button 2 to load images into the container, and then press 1 to unload them

The images do unload for me – I see this in that when I switch back to the second page the Loading: ... line appears again in the console. It takes a while for them to unload though: 60s.

I’ve run under Xcode as well now and can see the memory being released, as well as the textures unloading. Note that due to how the memory is managed you might not see it completely released, but at least new images won’t use more.

Ok. The problem for me though is that quite a lot of images are loaded within the lifetime of the app, and quite quickly I run out of memory on iOS. Is the released memory supposed to be able to be reused immediately after an image has been unloaded, or is there anything I can do to force purge?

(also, I dont see the Loading: … message in the console when running it as dotnetexe. Should I?)

In DotNet I’m not sure where the console logs will go.

If you need to free the images quicker you can create your own MemoryPolicy:

<MemoryPolicy ux:Global="QuickUnload" UnloadInBackground="true" UnusedTimeout="1" UnpinInvisible="true"/>

Then use QuickUnload as the MemoryPolicy on your images. The above has the same basic optons as UnloadUnused but with a quicker timeout.

If this doesn’t help then there’s likely something else consuming the memory that we’d have to investigate.

OK, thanks a lot, Ill try that out.

(Also, the normal console output is in the shell where i start the exe, however I didnt see the Loading… output)