polettix has asked for the wisdom of the Perl Monks concerning the following question:
What I really don't understand is why the process keeps growing demanding more memory as the index variable i increases.#include <EXTERN.h> #include <perl.h> #include <unistd.h> #include <stdio.h> void do_something () { dSP; ENTER; SAVETMPS; PUSHMARK(SP); eval_pv("$a = 1", 1); SPAGAIN; FREETMPS; LEAVE; } int main (int argc, char* argv[]) { PerlInterpreter *my_perl = perl_alloc(); char *embedding[] = {"", "-e", "0"}; I32 i; char c; perl_construct(my_perl); perl_parse(my_perl, NULL, 3, embedding, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; printf("Press a key to start\n"); read(0, &c, 1); for (i = 0; i < 1000000; ++i) do_something(); printf("Press a key to continue\n"); read(0, &c, 1); PL_perl_destruct_level = 1; perl_destruct(my_perl); perl_free(my_perl); printf("Press a key to exit\n"); read(0, &c, 1); return 0; }
After a suggestion from Joost (see below his response), I ended up finding that the following version of do_something shows less leakage (but not zero):
void do_something () { dSP; ENTER; SAVETMPS; eval_pv("$a = 1", 1); FREETMPS; LEAVE; }
What am I missing (apart from memory)?
Thank you in advance,
-- Flavio
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bare-bones embedding and memory leakage
by Joost (Canon) on Mar 16, 2005 at 15:23 UTC | |
by polettix (Vicar) on Mar 16, 2005 at 15:59 UTC | |
by dave_the_m (Monsignor) on Mar 16, 2005 at 17:36 UTC | |
by polettix (Vicar) on Mar 17, 2005 at 13:44 UTC | |
by polettix (Vicar) on Mar 18, 2005 at 17:32 UTC |