dispose/remove textures from memory

Oct 11, 2010 at 6:11 AM

I'm using Balder to create a Google Earth / NASA World Wind equivalent 3D earth viewer.  I started with a sphere, wrapped it with a 1024x2048 base texture, and made all the functions for converting back and forth between lat/lons, screen coordinates, and 3d coordinates.  For increasing resolution at closer zoom levels, I dynamically create map tiles that float just above the sphere's surface, and load the appropriate 512x512 textures from an external server.  This all works great, except that the memory usage keeps going up and up with each texture I load.  I really need a way to dispose/remove the textures that I'm not using anymore.  How can I do this?  I've tried the following so far without any luck:

  • calling Scene.RemoveNode(tile)
  • setting the tile.Material.DiffuseMap, tile.Material, and the tile Geometry to null, and calling GC.Collect()
  • extending the TextureManager class with a function named RemoveTexture(IMap map) that calls _textures.Remove(map) to attempt to remove the texture from the Dictionary
  • calling Runtime.Instance.Kernel.Get<TextureManager>().RemoveTexture(tile.Material.DiffuseMap)

Am I heading down the right path, or going about it all wrong?  Any assistance would be greatly appreciated.  Thank you!

Oct 11, 2010 at 9:32 AM


this is one of those things I really haven't thought about. 
The way you've gone so far is great, but there is a couple of vital places content is being held in addition. The ContentManager is in charge of loading content, it uses a system called ContentCache, this one does not have an evict at the moment, which it definitively needs.

If you want to extend it and want to share your result - you can email me the Mercurial patch when you're done (einar [at] dolittle [dot] com).


Hope this helps 

Oct 11, 2010 at 9:32 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.