Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Embedded Perl - Memory leak

by Molt (Chaplain)
on Oct 16, 2003 at 10:39 UTC ( #299706=note: print w/replies, xml ) Need Help??

in reply to Embedded Perl - Memory leak

You may want to look into making 'value' mortal. It's been a while since I touched internals but what I think is happening is that the newSVpvn() call is producing as SV with a refcount of one, when it's pushed onto the array this is going up to two, and hence going back down to one when the array is destroyed.. and not being destroyed.

I seem to recall this being discussed in "Extending and Embedding Perl", but I don't have my copy at work so can't check.

Replies are listed 'Best First'.
Re: Re: Embedded Perl - Memory leak
by rajiyer (Acolyte) on Oct 16, 2003 at 10:48 UTC
    Actually, I have tried making 'value' a mortal. If I do that, I will have to change:
    sv_free(av_delete(array, len, FALSE));
    av_delete(array, len, FALSE);
    otherwise, I get the error 'Attempt to free unreferenced scalar' on FREETMPS call. What this implies is that av_push does not increment the reference count of 'value'. Correct me if I am wrong.
      It was long time when I wrote Perl modules in C last time but IIRC av_push does increment the reference count. On the other hand I'm not sure why you need sv_free - av_delete should decrease reference counter of deleted SV itself. Try to add sv_dump() calls to check it yourself.

      Ilya Martynov,
      CTO IPonWEB (UK) Ltd
      Quality Perl Programming and Unix Support UK managed @ offshore prices -
      Personal website -

Re: Re: Embedded Perl - Memory leak
by Elian (Parson) on Oct 16, 2003 at 16:43 UTC
    You may want to look into making 'value' mortal.
    No. Never make things you put into an aggregate (or things you've fetched out of an aggregate) mortal. It messes up the refcounts, will result in things being prematurely destroyed, and in some cases may end up with unusual garbage inside the aggregates.

    Putting things into aggregates and taking them back out doesn't affect their refcounts.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://299706]
[LanX]: imagine the stock market if the choice for the second round would have been those two ...
[robby_dobby]: LanX: Not me. No YAPC in my country and the only one in Asia is so far off in Japan
[LanX]: Oh I thought "Misery" meant Missoury
[LanX]: where do you live?
[LanX]: YAPC Asia was renamed and you'd need to speak Japanese to be able to follow
[robby_dobby]: LanX: Misery :P
[robby_dobby]: Or India
LanX which means I can finally organize YAPC Asia in Sharm el Sheikh ;-)
[robby_dobby]: I attended a couple conferences (both in India). Left me with a renewed enthusiasm to do more, only to see it disappear in a few days!
[LanX]: Then come to YAPC EU in Amsterdam ...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2017-04-24 15:57 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (442 votes). Check out past polls.