Hi Joost, thank you for your kind response.

Actually, I don't see the point of defining the variable in the for cycle. You're assigning a value to a C variable, which actually has no reference count or implicit disposal; moreover, the Perl interpreter has no clue about what you're going to do with the return value (unless you tell it).

What I'm saying is that your code is equivalent to the following cycle:

for (;;) { ENTER; SAVETMPS; eval_pv("1;", TRUE); FREETMPS; LEAVE; }
which has no explicit handling of the return value of eval_pv.

But I still thank you because your suggestion actually made me think: why do I need PUSHMARK(SP) and SPAGAIN? I removed them and... I had less leakage. (BTW, I'm going to modify my original post to include this enhancement).

Yes, less but not zero leakage. When my program starts, now, it has the following memory footprint (i.e. what you get before the first "read"):

Name: embed01 Pid: 13386 FDSize: 256 VmSize: 2696 kB VmLck: 0 kB VmRSS: 940 kB VmData: 256 kB VmStk: 8 kB VmExe: 836 kB VmLib: 1516 kB
When I let the program go, I notice an increment in VmSize of around 4 kB every million iteration i let go; so, after 4 million iterations, I get:
Name: embed01 Pid: 13386 FDSize: 256 VmSize: 2712 kB VmLck: 0 kB VmRSS: 1056 kB VmData: 272 kB VmStk: 8 kB VmExe: 836 kB VmLib: 1516 kB
that is a quite subtle leak IMHO but still a leak. Note that the memory increase is quite slow and time-linear, i.e. if I stop at 2 million iterations I get 2704 kB or something similar.

This is quite an improvement with respect the previous version, but my question remains more or less the same: where is it leaking? Moreover: if I'll ever actually need PUSHMARK(SP) and SPAGAIN... how will I avoid leakage?

TIA, --Flavio


In reply to Re^2: Bare-bones embedding and memory leakage by polettix
in thread Bare-bones embedding and memory leakage by polettix

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.