Anyone attempt animating a ModelFeature and discover memory issues? I get a steady rapid memory leak when i periodically change the Latitude property of a ModelFeature.
But, the condition for the memory leak is apparently assignment to a different value. When i assign a constant value to Latitude periodically i don't get a memory leak, nor do I when I comment out the assignment line from the memory-leak-version of my test while leaving everything else the same.
Thanks to patmurris for providing the solution to my problem:
18:14:54 < patmurris> do you rebuild the mesh... and forgot to dispose() of old stuff ?
Sorry that I didn't realize you'd given me the answer at the time. The sequence of events that caused the memory leak:
(1) ModelFeature.Update(...) calls Initialize often because, since I'm changing the lat and lon often, the condition
(currentElevation != World.TerrainAccessor.GetElevationAt(Lat itude, Longitude))
evaluates to true often
(2) ModelFeature.Initialize(...) calls LoadColladaMesh(...)
(3) ModelFeature.LoadColladaMesh(...) doesn't call dispose on the existing meshes in the ModelFeature before creating new ones.
For now my solution is adding this:
to the ModelFeature constructor, and adding this:
this.meshElems = null;
to ModelFeature.LoadColladaMesh(...) after
if (meshElems != null)
foreach (MeshElem me in meshElems)
if (me.mesh != null)
if (me.meshTextures != null)
foreach (Texture t in me.meshTextures)
if (t != null)
My understanding is that this memory leak would affect animation and also changes in the vertical exaggeration, because changes in either would cause ModelFeature.Update(...) to call ModelFeature.Initialize(...). I also believe that ModelFeature.LoadDirectXMesh(...) should be updated similarly (I haven't tested that).
if (meshCount == 0)