0

I'm planning on making a game engine in C++ and DirectX 9. So I'm just testing out the features in Direct3D. My problem is that when i render objects with the Direct3DX functions, (text, textures, meshes) the app's memory usage keeps going up and my PC's performance goes down. When I just have a cleared scene without anything rendering, the memory usage stays around 4mb but when I add text or meshes (even with the predefined mesh drawing functions i.e. D3DXCreateBox, D3DXCreateTeapot) the problem mentioned above occurs. Can anyone help me fix it? NOTE: When i'm not rendering in a loop, the memory usage stays at 9mb, but of course, everything stays static.

  • 2
    How are you measuring memory usage? FYI Task Manager is pretty much useless for that purpose. And besides, there are countless ways memory leaks can happen. We can't help you unless you give us a [Short, Self Contained, Correct (Compilable), Example](http://www.sscce.org/). – In silico Nov 21 '12 at 21:20
  • Code sample? I haven't used DirectX but from what you are saying there must be a need to clear the scene before rerendering... – nonsensickle Nov 21 '12 at 21:20
  • Don't use pointers. Don't use `new`. – Kerrek SB Nov 21 '12 at 21:21
  • 1
    @KerrekSB With DirectX you need to use pointers because graphics resources are reference-counted objects. Though it's certainly better to use smart pointers than raw pointers (but only if you need a strong reference). –  Nov 21 '12 at 21:35
  • 1
    @user1775315: In that case design a robust, sane wrapper (something [like this](http://codereview.stackexchange.com/questions/4679/shared-ptr-and-file-for-wrapping-cstdio-update-also-dlfcn-h) for instance) and use that, I'd say. – Kerrek SB Nov 21 '12 at 21:59
  • 1
    @KerrekSB The Direct3D API is already perfectly robust and sane. Graphics resources are inherently non-copyable, so you need a different ownership mechanism. And intrusive reference-counting (the COM way) is better than non-intrusive reference-counting (the shared_ptr way). –  Nov 21 '12 at 22:15

1 Answers1

2

Are you calling IUnknown::Release on D3D interface pointers when you're done using them? Using a smart pointer class such as ATL's CComPtr helps avoid these issues.