Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory

by gellyfish (Monsignor)
on Jul 10, 2006 at 09:23 UTC ( #560101=note: print w/ replies, xml ) Need Help??


in reply to Re: perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory
in thread perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory

You will find these things in the perl source code. newAV() is defined in av.c. The struct av is defined in sv.h and the typedef struct av AV; is in perl.h

/J\


Comment on Re^2: perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory
Select or Download Code
Re^3: perlembed: mortalize an AV, get "Attempt to free unreferenced scalar" - don't mortalize, leaks memory
by Moron (Curate) on Jul 10, 2006 at 12:57 UTC
    I have now found a copy of the source of av.c at sourceforge updated version and my first second impression is that an explicit call to av_clear Perl_av_clear is required to free the memory.

    -M

    Free your mind

      You probably actually wanted a more recent copy of the source. av_clear doesn't free the memory allocated to the array nor does it free the SVs that form its elements. It simply truncates the array.

      /J\

        Amended accordingly (studying the version you cite av_clear appears to have been renamed to Perl_av_clear and the new av_clear has another purpose).

        -M

        Free your mind

        nor does it free the SVs that form its elements

        moron is partially correct, it does free the SV's that form its elements. Although indirectly via refcount decrement. Thats what the follow code does:

        while (index) { SV * const sv = ary[--index]; /* undef the slot before freeing the value, because a * destructor might try to modify this array */ ary[index] = &PL_sv_undef; SvREFCNT_dec(sv); }
        ---
        $world=~s/war/peace/g

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://560101]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-08-30 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls