49k Should Be Enough for Anyone

chromatic on 2008-01-20T08:21:22

My name is chromatic and I'm addicted to Valgrind. I fixed up "Hello, world!" in Parrot a few days ago so that it has no memory leaks and that felt good. Tonight I decided to see how the same program fares in Rakudo:

$ valgrind --suppressions=/home/chromatic/dev/parrot/tools/dev/parrot.supp --num-callers=500 --leak-check=full --leak-resolution=high --show-reachable=yes ../../parrot --leak-test perl6.pbc -e 'say "Hello, world!"'
LEAK SUMMARY:
    definitely lost: 28,206 bytes in 361 blocks.
    indirectly lost: 41,811 bytes in 218 blocks.
      possibly lost: 0 bytes in 0 blocks.
    still reachable: 20 bytes in 1 blocks.
         suppressed: 0 bytes in 0 blocks.

A lot of that came from the allocation of a new hash for each LexPad PMC. Hash memory (not Hash PMC memory) currently comes from malloc(), not GCable memory pools, so for each hash you create, you need to free it. I added a destroy() vtable entry to LexPad and set the active destroy flag in the initializer. Success!

$ vgp perl6.pbc -e 'say "Hello, world!"'
LEAK SUMMARY:
    definitely lost: 19,406 bytes in 161 blocks.
    indirectly lost: 211 bytes in 18 blocks.
      possibly lost: 0 bytes in 0 blocks.
    still reachable: 20 bytes in 1 blocks.
         suppressed: 0 bytes in 0 blocks.

There's still more work to do (though much of what remains is in the difficult-to-diagnose IMCC), but five new lines of code cut out a whole swath of problems. (Yes, vgp is a shell alias. I wouldn't type that by hand more than once.)


Valgrind

djberg96 on 2008-01-20T14:10:59

The world needs a book on Valgrind. Srsly.

Re:Valgrind

chromatic on 2008-01-20T18:07:07

Agreed. I'd be the first in line to buy one, and I tend to get books for free. I'll look into this again.