in reply to Handing Memory Leaks due to XS holding on to references

When I'm writing C, I typically have structures like this:
#ifdef DEBUG_MEM fprintf(memlog, "malloced(%d)\n", pointer); #endif #ifdef DEBUG_MEM fprintf(memlog, "freed(%d)\n", pointer); #endif

Then I use perl to analyze the logfile. You can't just do it with eyeballs, because sometimes the same memory gets malloc()ed and freed a few times. Also, with XS, it's a little less explained what's happening when which macro is called... but the strategy is sound -- even if it's a small-project kind of strategy.

I also think, trying to do the demalloc in DESTROY is the wrong approach. It would be better to pull as much of the XS up into perl as possible. If you want automatic, use perl. If you want explicitly-detailed-and-micromanaged, use XS/C.

-Paul

Replies are listed 'Best First'.
Re^2: Handing Memory Leaks due to XS holding on to references
by ikegami (Patriarch) on Aug 28, 2009 at 14:21 UTC
    valgrind is a tool to detect memory leaks and overflows, and it works with Perl.