On Mon, Jan 08, 2007 at 06:16:57PM +0000, Alberto Simões wrote:
> Hi
> 
> I am trying to debug some code that is using too much memory. I am not 
> sure if it is from the XS code, but if you say it isn't at least I know 
> I should look elsewhere.
> 
> Here it is (resumed):
> 
>    array = newAV();

> 
>         RETVAL = newRV_noinc((SV*)array);
>     OUTPUT:
>         RETVAL
> 
> Am I doing something wrong? Maybe because of refcounts and such?

Yes, I think so. (But I'm not the expert on these)

Perl's stack is not refcounted, so whatever picks up the RV that you passing
to RETVAL will bump that RV's reference by 1, when it takes ownership.
Hence (I think) you're leaking a reference to that RV, and it will never
get freed. I think that you need this:

        RETVAL = sv_2mortal(newRV_noinc((SV*)array));

to mark the initial single reference on that RV as something that will need
cleaning up "soon".

Nicholas Clark

Reply via email to