Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problem with meomory-leaks

problem with meomory-leaks

problem with meomory-leaks


I'm new to managed DirectX and have a great problem with memory leaks.
I think, its the best when I tell you something about the project and the
structure of the project.

The goal of the project is to render a scenegraph in a control ( I use a
panel as control, because I mentioned, that the picture box is buggy for
Becuase there can be a lot of different objects I have written an own class
for rendering. The class is named RenderMain and is established in an own
assembly with other classes. This class has a property for the device and a
property for the control. The Mainform is established in an other assembly.

I'd overriden the OnPaint-Method of the Mainform like this:


protected override void OnPaint(PaintEventArgs e)
    if (m_RenderMain!=null)
The Methode m_RenderMain.PaintDevice() looks like this:


public void PaintDevice()
    m_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
    if (m_IsViewpointDefined==false)
    if (m_IsLightDefined==false)
In the RenderScenegraph I render all items of the scenegraph. For this
purpose, every item of the scenegraph have a method which looks like thius:


public Device Action(Device directXDevice)
    //render item
    return directXdevice;
The device is initialised in the following method of the RenderMain class.


public void InitializeDevice()
    PresentParameters myPresentParameters= new PresentParameters();
    int adapterOrdinal=Manager.Adapters.Default.Adapter;
    CreateFlags flags= CreateFlags.SoftwareVertexProcessing;

    //Check to see, if we can use a pure hardw<redevice
    Caps caps=Manager.GetDeviceCaps(adapterOrdinal,DeviceType.Hardware);
    if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
        //Replace softwarevertex with hardwarevertex
    //Do we support pure device?
    if (caps.DeviceCaps.SupportsPureDevice)
        flags |=CreateFlags.PureDevice;

All works fine and the graphical objects are rendered, but if I start the
taskmanager, I see, that the memory-use is increasing by every repaint of
the Mainform.
This is happening, everytime when I'm using the device in any form.
I'd tried to place the methods InitializeDevice and RenderScenegraph in the
Mainform but without any effects.

So my question is, can anyone help me, to solve the problem of increasing

cu Thomas

RE: problem with meomory-leaks

I am not a direct x programmer but I do know that when you are using device contexts in C++ and you select an object into them, you must later select the return value back in.  For example

CBitmap* pOldBMP = myDC.SelectObject(&myBitmap);
... do stuff
// end function

As I said, I dont yet program directX and my post may be way off but it was worth a shot.


RE: problem with meomory-leaks

I generally use C++ for DirectX stuff, but I've used C# once or twice so I'll see if I can help.  First of all, you shouldn't be calling DoEvents() and Invalidate() in your OnPaint method.  That should go in a while loop in Main().  Since C# is garbage collected, you can clean up your leak by calling GC.Collect() every now and then, but you shouldn't have to do this.  My advice is comment out lines until you find exactly what method is causing this so that we can have a better idea of what's going on.  All I could guess is that you are somehow calling InitDevice() more than once.

RE: problem with meomory-leaks

Well, the leak happens ever, when I use the device.
Even if I setup the camera.

I need the DoEvents call, because the application work on a control in a form. If I don't use the DoEvents call, all other components of the form aren't rendered correctly.

cu kostarsus.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close