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:
which has no explicit handling of the return value of eval_pv.for (;;) { ENTER; SAVETMPS; eval_pv("1;", TRUE); FREETMPS; LEAVE; }
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"):
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: 2696 kB VmLck: 0 kB VmRSS: 940 kB VmData: 256 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.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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |