Just wanted to let you know that I've found the solution already. After
playing around with it I have discovered that fix is in adding
ENTER;SAVETMPS;FREETMPS;LEAVE fixes the problem.

So

 for(i = 0; i < 1000; i++)
 {
     SV * sub;
     char text[256];
     ENTER;
     SAVETMPS;
     sprintf(text, "$sub = %d;", i);
     sub = eval_pv(text, TRUE);
     FREETMPS;
     LEAVE;
     sleep(1);
 }

does not leak memory. Anyway, thank you for all replies.

Andrei

On Thu, Feb 20, 2003 at 03:05:26PM +0100, [EMAIL PROTECTED] wrote:
> Hi!
> 
> I hope this is the right list for this question. If not, please direct to
> appropriate one.
> 
> My problem is simple. I'm embedding perl into my C program (perl 5.6.1).
> I noticed that when I use eval_pl in my code then my program leaks memory. So
> finally I reduced my program to do the following.
> 
> for(i = 0; i < 1000; i++)
> {
>     SV * sub;
>     char text[256];
>     sprintf(text, "$sub = %d;", i);
>     sub = eval_pv(text, TRUE);
>     sleep(1);
> }
> 
> I'm loosing approximatly 1K on each iteration. What is the problem here? I
> tried to SvREFCNT_dec(sub), but this leads to "Attempting to free unreferenced
> scalar." warning from perl and does not stop the leak. Is there any way to
> avoid it?
> 
> Andrei
> 
> PS. I'm not subscribed to the list. Please include my address in the CC field
> when replying

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to