This project is read-only.

Question for memory management in Xen

Aug 30, 2010 at 1:46 PM

Hi.

I tested how allocated memory managemented in xen.

for this test, i create simple game application with some loop.

public override void Draw(DrawState state)
        {
            DebugDrawManager.Instance.Visible = false;
            if (flag)
            {
                for (int i = 0; i < 100; ++i)
                {
                    Vector3[] vectors = new Vector3[3];
                    vectors[0] = new Vector3(0, 0, 0);
                    vectors[1] = new Vector3(0, 0, 0);
                    vectors[2] = new Vector3(0, 0, 0);

                    IVertices vertice = new Vertices<Vector3>(vectors);
                    vertice.Dispose();

                }
            }
        }

And I used DrawStatisticsDisplay for check to allocated memory.

as a result, allocated memory is rising, not keeping. Even though i tried to force GC.Collect(), allocated memory is not perfectly collected.

When run GC.Collect(), some allocated memory is collected, but entire alloated memory is still not collected.

this problem occured only with IVertices, Xen.Ex.Geometry's shapes, etc... (and also Xen tutorial 23).

and run this application long term, program is crashed with OutOfMemoryException.

I want that how to dispose perfectly IVertices (or Xen.Ex.Geometry, etc...).

thanks.

Sep 4, 2010 at 10:29 PM

Every resource will consume a small amount of memory, as a weak reference is created for tracking purposes (for the overlay). This doesn't get cleaned up, but it's a very small amount of memory. If you are creating 100s of resources every frame, then yes, memory usage will slowly go up - but not dramatically so. I am not aware of any resource memory leaks that do occur - just creating a vertices<> object like that will not cause any leaks beyond the weak reference (the internal XNA vertex buffer won't be created in your example code).

I would highly suggest using the CRLProfiler to track this down. This can give you very exact memory timelines, and it will often be very clear where memory is being kept alive. (There are some tricks to get it work, eg, running the profiler as admin). If you do find it's a xen resource please let me know, but it's not something I'm aware of and I was pretty careful with this sort of thing when building the core classes.

Thanks (and again, sorry for the slow reply)

Sep 5, 2010 at 12:39 AM

thanks for your answer, StatusUnknown.

I solved this problem with Dynamic Geometry in tutorial 05. Instead of create new IVertives for each frame, Reuse static IVertices with SetDirty().

Actually, i tested that create 500000 new IVertices instance for each frame :). it's kind of stress test.