Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Handing Memory Leaks due to XS holding on to references

by jettero (Monsignor)
on Aug 28, 2009 at 10:38 UTC ( [id://791867]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://791867]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found