Debugging a Memory Leak
    Maxime Chevalier-Boisvert via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Mon Nov 17 15:12:08 PST 2014
    
    
  
There seems to be a memory leak in the Higgs compiler. This 
problem shows up when running our test suite (`make test` 
command).
A new VM object is created for each unittest block, e.g.:
https://github.com/maximecb/Higgs/blob/master/source/runtime/tests.d#L201
These VM objects are unfortunately *never freed*. Not until the 
whole series of tests is run and the process terminates. The VM 
objects keep references to many other objects, and so the process 
keeps using more and more memory, up to over 2GB.
The VM allocates it's own JS data heap that it manages itself, 
i.e.:
https://github.com/maximecb/Higgs/blob/master/source/runtime/gc.d#L186
This memory is clearly marked as NO_SCAN, and so references to 
the VM in there should presumably not be counted. There is also 
executable memory I allocate with mmap, but this should also be 
ignored by the D GC in principle (I do not mark executable code 
as roots):
https://github.com/maximecb/Higgs/blob/master/source/jit/codeblock.d#L129
I don't know where the problem lies. There could be false 
pointers, but I'm on a 64-bit system, which should presumably 
make this less likely. I wish there was a way to ask the D 
runtime "can you tell me what is pointing to this object?", but 
the situation is more complex because many objects in my system 
refer to the VM object, there is a complicated graph of 
references. If anything points into that graph, the whole thing 
stays "live".
Help or advice on solving this problem is welcome.
    
    
More information about the Digitalmars-d-learn
mailing list