How do you know you have a memory leak?

Some tips, dont use XPUSHs, the amount of elements you will push is preknown, do a single EXTEND then do the loop. I try never use malloc or safemalloc or Newx in my XS code. Use alloca, or "char * buf = sv_grow(sv_newmortal(),size);" which is functionally identical but slower. croaks and dies in XS will memory leak all malloced blocks and leak all C++ objects (stack and heap), since free or the c++ destroyer is never called, only Perl SV mortals and C stack allocated bytes will be freed during a perl croak or die (which is implemented with longjmp. You choices for safe XS allocation are alloca, mortal SVs, or package SVs or incoming @_ SVs. I dont see any croaks or dies in your XS code that would cause leaking. I didn't read the C++ function you posted. I would say XS is easy. Your best kept secret debugging is to code format the post c preprocessor output of your XS code. All the secrets of the XS api will be revealed. And of course use a C debugger and compile the XS library with -Od and with symbols.

In reply to Re: xs memoryleak by bulk88
in thread xs memoryleak by yarp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.