My C# app is running out of memory and after hunting it down i discovered that it was where i was doing the following:
SlimDX.Direct3D9.VertexDeclaration Declaration = new SlimDX.Direct3D9.VertexDeclaration(Render.Device, Elements); SlimDX.Matrix WVP; WVP = SlimDX.Matrix.Identity; WVP = SlimDX.Matrix.Multiply(WVP, m_Transform); WVP = SlimDX.Matrix.Multiply(WVP, Render.Camera.ViewTransform); WVP = SlimDX.Matrix.Multiply(WVP, Render.Camera.ProjectionTransform); Effect.SetValue(new SlimDX.Direct3D9.EffectHandle("matWorldViewProjection"), WVP.ToArray()); Effect.SetValue(new SlimDX.Direct3D9.EffectHandle("bOverrideColour"), m_bOverrideColour); Effect.SetValue(new SlimDX.Direct3D9.EffectHandle("OverrideColour"), m_OverrideColour); Effect.CommitChanges(); Render.Device.VertexDeclaration = Declaration; Render.Device.DrawUserPrimitives(SlimDX.Direct3D9.PrimitiveType.LineList, 1, Verts); Declaration.Dispose();
I know that creating vertex declarations on the fly is not wise, this is temporary code. Now, the leak occurs when i don't manually Dispose() of the vertex declaration.
I bring this up for 3 reasons:
1) I am now a bit confused about when i should Dispose() manually and when i shouldn't. My impression was that if i know i dont need it any more and want it cleaned up, i Dispose() it. Otherwise the GC does it. Is this correct?
2) I thought there is a chance that this is a bug in SlimDX, though i doubt it.
3) There is a documentation error for Direct3D9.Device.VertexDeclaration. It states that a Result is returned when it's a property.
Thanks guys,