Copy or sever are the Right way to release an old PDL. As you surmise, if you slice a PDL the original stays around until the slice gets released. Severing or copying the slice (both do essentially the same thing) releases the original PDL, which then gets GC'ed by perl.

Maintaining the connection between two PDLs requires a small but nonzero bit of overhead, even if the original PDL is an "orphan". For example, the following is a Bad Idea:

        $a = zeroes(1e6+1);
        for $i(1..1e6){
                $a = $a->(1:);
        }

You definitely want to do something like

                $a = $a->(1:)->sever;
in the loop instead.
        

On May 28, 2007, at 8:17 PM, Trevor Carey-Smith wrote:

Hi,

I have a memory usage/garbage collection question. When you overwrite a piddle with a (smaller) part of itself, what happens to the original piddle? Is it still in memory? i.e. what happens in each of the following cases?

perldl> $a = sequence(10)
perldl> $a = $a(0:4)

perldl> $b = sequence(10)
perldl> $b = $b(0:4)->copy

perldl> $c = sequence(10)
perldl> $c = $c(0:4)->sever

Or is there a better way of dropping unwanted parts of a piddle?

Thanks,
Trevor.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl


_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to