Re: Memory issues
- From: smallpond <smallpond@xxxxxxxx>
- Date: Sat, 29 Mar 2008 08:58:51 -0700 (PDT)
On Mar 29, 11:12 am, jm <j...@xxxxxxxxx> wrote:
smallpond a écrit :
On Mar 29, 10:10 am, jm <j...@xxxxxxxxx> wrote:
smallpond a écrit :
On Mar 29, 8:45 am, jm <j...@xxxxxxxxx> wrote:It is interesting, but it does not seam to solve my substitution issue.
Based on the fact that perl contains many memory leaks,perldoc perlfaq3
A universal way to measure how many memory is malloced is required.
Is there standard way to measure how many memory a process has
allacated, which run with cygwin perl, active perl, and strawberry perl?
This should help to localize which code makes memory leaks.
See:
How can I make my Perl program take less memory?
How can I free an array or hash so my program shrinks?
However I does not understand this:
« Memory allocated to lexicals (i.e. my() variables)
cannot be reclaimed or reused even if they go out of scope. It is
reserved in case the variables come back into scope. Memory allocated
to global variables can be reused (within your program) by using
undef()ing and/or delete(). »
Aren't my variables local variables?
Why aren't they freed when function terminates?
sub foo {
my $v = 5;
return \$v;
}
In C, once the function terminates $v is gone and a pointer
to it will fail. In perl this reference is legal and the
space will not be reclaimed.
In your sample of code above, when you pass a string to a sub,
perl will make a copy. If you pass a reference it will not.
This isn't a memory leak in perl, it's a memory leak in your
program.
As you suggested, I tried to replace scalar by references, but this does
not look like saving memory (might be 10 Mbytes, I mean just the size of
the main variable):
The sub call was just answering your question about
locals.
Each of these:
$$d =~ s/x(.....)/$1a/g ;
is making string copies in $1. $1 is a persistent
variable. perl 5.10 has new regex syntax for
avoiding use of $1, $2 etc.
.
- References:
- Memory issues
- From: jm
- Re: Memory issues
- From: smallpond
- Re: Memory issues
- From: jm
- Re: Memory issues
- From: smallpond
- Re: Memory issues
- From: jm
- Memory issues
- Prev by Date: Re: Memory issues
- Next by Date: Re: Readline using foreach and while
- Previous by thread: Re: Memory issues
- Next by thread: FAQ 7.24 How can I catch accesses to undefined variables, functions, or methods?
- Index(es):
Relevant Pages
|