Im writing a XNA program that display pictures from a specific picture album on the Zune. The problem is when if I load the textures from all the pictures in the album, the program runs out of memory. I tried loading one by one and call Dispose on the previous picture texture once the user moves on to the next picture. This works but then I cannot get back the texture from the previous picture once it is disposed so the user cannot view back the past pictures without restarting the program!
Don't store the texture handle per item in your album. Instead, use a single program-level handle that you dispose and load as needed as the user walks through the album.
I would suggest doing all your data processing just once, and storing the filename (so you only have to do all your hierarchy/sorting once). Then only load a picture when you want it (exactly what the previous post suggested).
The problem with this method is that Content.Load(string) will load your texture, however if you lose all pointers to the texture the ContentManager will keep the texture in memory so that if you load it again it will load instantly. There is a method Content.Unload() which will drop these cached items, see:
A forum discussion on this topic:
http://forums.xna.com/forums/p/25978/141761.aspx
Shawn Hargreaves explains it:
http://blogs.msdn.com/shawnhar/archive/2006/09/06/743437.aspx
The way I would implement this is either to call unload every time you stop using a picture, or if you want faster loading (this depends on how often a user changes picture, if they're meant to be flicking through picture really quickly unloading every time is a bad idea) try catching out of memory exceptions and only calling unload then.