Memory usage increases through retained references to Spaces
Posted: Mon Jan 10, 2011 11:29 pm
What ho,
I've noticed that on repeatedly entering and leaving levels in my project, memory usage is increasing by several hundred K a time. (This was substantially larger, but the rest was entirely due to my own inability to manage memory...) I'm forcing full garbage collections on entering and leaving levels to spot these issues.
What appears to be happening is that on entering the level I create a new Space; on leaving I Dispose() of that Space and forget all references to it. But this isn't making the Space go away, so it and everything to which it still refers cannot be garbage collected.
I can mitgate the situation slightly by manually removing all entities and updateables from the Space before disposing it. However this doesn't solve the problem entirely.
My profiler tells me that what's happening is that when CollisionPairs are returned to their pool, whilst their references to ParentA and ParentB etc. are cleared, their reference to the owning Space is retained. So the static Resources class' SubPoolCollisionPair list is keeping my Space alive.
Incidentally most of the memory thus retained seems to belong to the Space's MotionStateManager, in particular its WriteBufferItem structs.
I suspect this is a loaded question, but is there a way of preventing this? If not, I guess I'm reporting it as a potential bug.
In the short term I imagine I might be able to mitigate the problem by retaining my own pool of Spaces and ensuring I clear them out after use. Since all my levels have similar characteristics, physicswise, this may not be too problematic. Any thoughts gratefully received!
All the best,
-eg.
I've noticed that on repeatedly entering and leaving levels in my project, memory usage is increasing by several hundred K a time. (This was substantially larger, but the rest was entirely due to my own inability to manage memory...) I'm forcing full garbage collections on entering and leaving levels to spot these issues.
What appears to be happening is that on entering the level I create a new Space; on leaving I Dispose() of that Space and forget all references to it. But this isn't making the Space go away, so it and everything to which it still refers cannot be garbage collected.
I can mitgate the situation slightly by manually removing all entities and updateables from the Space before disposing it. However this doesn't solve the problem entirely.
My profiler tells me that what's happening is that when CollisionPairs are returned to their pool, whilst their references to ParentA and ParentB etc. are cleared, their reference to the owning Space is retained. So the static Resources class' SubPoolCollisionPair list is keeping my Space alive.
Incidentally most of the memory thus retained seems to belong to the Space's MotionStateManager, in particular its WriteBufferItem structs.
I suspect this is a loaded question, but is there a way of preventing this? If not, I guess I'm reporting it as a potential bug.
In the short term I imagine I might be able to mitigate the problem by retaining my own pool of Spaces and ensuring I clear them out after use. Since all my levels have similar characteristics, physicswise, this may not be too problematic. Any thoughts gratefully received!
All the best,
-eg.