Game Development Community

T2DShape3D leaking memory? [Resolved]

by David A Young · in Torque X 2D · 07/12/2009 (3:20 am) · 5 replies

I have a component that creates a T2DShape3D and to the best of my ability try to get rid of it on _OnUnregister()

_3dObject.MarkForDelete = true;
_3dObject.Dispose();
_3dObject = null;

But for some reason the 3d Object remains in memory.
When I clone this component many many times, I eventually get an exception thrown from XNA saying I've run out of video memory.

#1
07/12/2009 (9:09 pm)
If there's an active reference to it in the TorqueObjectDatabase, it may be hung onto there. Also, if you have another list or global reference to it, it can hang on.

The pattern you are showing above would be right if this was the only reference to it anywhere.
#2
07/12/2009 (9:47 pm)
Well my full unregister method is

protected override void _OnUnregister()
        {
            // todo: perform de-initialization for the component

            TorqueObjectDatabase.Instance.Unregister(_3dObject);

            // failed attempt to delete the 3d objects.
            _3dObject.MarkForDelete = true;
            _3dObject.Dispose();
            _3dObject = null;

            base._OnUnregister();
        }

I have no idea what's holding onto the T2DShape3D object.
#3
07/13/2009 (1:17 pm)
After using a memory profiler it seems that the leak is not inside of T2DShape3D but inside

InternalResource, namespace Garagegames.Torque.Core

It looks like the T2DShape3D class is calling

Call Stack
ResourceManager.CreateIndexBuffer(DynamicIndexBuffer, D3DIndexBufferProfile, int)
Mesh.CreateVBIB()
Shape.CreateVBIB(GraphicsDevice)
ShapeInstance.Render(int, float, Vector3, SceneRenderState, int)
T2DShape3D.Render(SceneRenderState)
T2DSceneGraph._RenderObjects(TorqueObjectType, float)
...

But..

InternalResource<DynamicIndexBuffer>
DynamicIndexBuffer
InternalResource<DynamicVertexBuffer>
DynamicVertexBuffer

Just keep growing in numbers without ever being removed.

Namespace: GarageGames.Torque.Core
Name: BaseResource[]

Is the only thing that is holding a reference to the Dynamic...Buffer objects.
#4
07/17/2009 (9:43 am)
Ok I figured out the problem. So apparently if you "Pool with Components" on a template and a T2DShape3D is created and disposed of within the component for some reason Torque still has a

InternalResource<DynamicIndexBuffer>
DynamicIndexBuffer
InternalResource<DynamicVertexBuffer>
DynamicVertexBuffer

That will never disappear. Solution: Don't pool components that contain T2DShape3D objects.
#5
07/17/2009 (9:54 am)
Interesting find, David.