Tassilo von Parseval wrote:
On Thu, Oct 30, 2003 at 08:02:53PM +1100 Sisyphus wrote:

Nick Ing-Simmons wrote:


SV *
my_xsub()
CODE:
{
RETVAL = sv_2mortal(newSVpv(string,strlen(string));
}
OUTPUT:
RETVAL


As regards that, Nick - is the 'sv_2mortal' part necessary ?


I thought *not* - but I'm sometimes wrong :-)


It is. If you have code like

    {
        my $var = my_xsub();
        ...
    }

and want $var to be cleaned up when it falls out of scope, you have to
make it a mortal. Mortals are just variables that clean up themselves
when their reference count goes to zero.


I still question that - and hope that in so doing I don't raise your anger. (That's not what I'm trying to do :-)


But if I run as Inline C code:

SV* dumb(char * s) {
    return newSVpv(s, 0);
    }

With perl code:

my $d = 'a' x 1000000;
for(0..1000) {
    my $string = dumb($d);
    print ".";
    sleep 1;
    }

Then I don't observe any memory leak. I can see the memory usage jump when the program starts, but it remains steady as the loop goes through its iterations.

If you are correct, I would have expected to see memory usage increase every second.

My view that 'sv_2mortal' is not required in this instance is also supported by some sample code and discussion contained in the fine book by Jenness and Cozens.

If I'm missing something I hope someone can point at the fallacy(s) in my thinking.

Cheers,
Rob


--
Any emails containing attachments will be deleted from my ISP's mail server before I even get to see them. If you wish to email me an attachment, please provide advance warning so that I can make the necessary arrangements.




Reply via email to