Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


DirectX + C# + my prgoram = Memory Leak?

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using C# and DirectX to create a 3d drawing program. I am having a problem because memory is continualy being alloced. I am using up to half a gig every 5 minites. This is when I have very few vertices in use. This is my rendering code - a_Dev.SetStreamSource( 0, m_vertexBuffer, 0); a_Dev.VertexFormat = CustomVertex.TransformedColored.Format; a_Dev.DrawPrimitives(PrimitiveType.LineStrip , 0, points.Count-1); Is there anything wrong with it? This is the only code that is being repeatidly called. Other than the main rendering body which should be ok. I am using a Composition of objects. Each object can have children and each object is required to render itself. Thank you for your time, Arrummzen

Share this post

Link to post
Share on other sites
Well, I don''t know C#, but I think its GC only gets tripped up if you continually create objects in a loop. Check for that.

Share this post

Link to post
Share on other sites
I added a call to the gc before the rendering, but I am still having the problem.

How do you recomend I fix this?

Im not creating objects in a loop.

This is my actualy render function -
public void Render()
if (myDev == null)

System.GC.Collect ( );

myDev.Clear(ClearFlags.Target, System.Drawing.Color.Black , 1.0f, 0);


//Begin the scene

// Rendering of scene objects can happen here
m_Doc.Render ( myDev );

//End the scene

EDIT: I don't think its a problem with the C# GC. I think somehow one of the componets in the DirectX API is allocing some memory somewere that I should be freeing by a call to a directX object...

Thank you for your time,

[edited by - Arrummzen on April 21, 2004 11:43:10 PM]

Share this post

Link to post
Share on other sites
In addition this code is also being called

m_vertexBuffer = new Microsoft.DirectX.Direct3D.VertexBuffer(typeof(CustomVertex.TransformedColored), points.Count , a_Dev, 0, CustomVertex.TransformedColored.Format, Pool.Default);
m_vertexBuffer.Created += new EventHandler ( OnCreateVertexBuffer );
this.OnCreateVertexBuffer ( m_vertexBuffer , null );

private void OnCreateVertexBuffer(object sender, EventArgs e)
VertexBuffer vb = (VertexBuffer)sender;
GraphicsStream stm = vb.Lock(0, 0, 0);
CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[points.Count];

for ( int itr = 0 ; itr < points.Count ; itr++ )
verts[itr].X = ((D3DPoint)points[itr]).p_x;
verts[itr].Y = ((D3DPoint)points[itr]).p_y;
verts[itr].Z = ((D3DPoint)points[itr]).p_z;
verts[itr].Rhw= 1;
verts[itr].Color = ((D3DPoint)points[itr]).p_color.ToArgb();



Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!