title: Debugging memory usage in D
body: <p>I've written a program in D which makes heavy use of pointers, as well as <code>std.container.Array</code> and <code>std.container.BinaryHeap</code>, along with a bunch of structs I have written myself, to implement a treelike structure. All of my pointers are returned either using <code>new</code> or by aliasing existing pointers.</p>
  
  <p>I'm trying to test the program, which involves running the same operation many times (1000 or so), which involves allocating and deallocating quite large trees of structs inside a loop (binary trees with 100,000 leaves or so).</p>
  
  <p>I'm finding that this is causing <em>huge</em> memory leaks, by which I mean 6+ GB of RAM being consumed (before the program crashes). I'm a bit baffled as to why. I've tried using Valgrind to find the source of the problem, but it's not being particularly helpful, as it can't demangle D names, so I can't even see what's leaking.</p>
  
  <p>Could anyone suggest how I can begin to tackle this problem? I'm not used to this kind of thing in a high-level language. I use GDC with GCC 4.9.1 to compile my code, with <code>-O3 -g -pg -frelease</code> as compiler options.</p>