Re: Memory issues
- From: Joost Diepenmaat <joost@xxxxxxxxx>
- Date: Sun, 30 Mar 2008 01:13:14 +0100
jm <jm@xxxxxxxxx> writes:
Modifying a little bit again the script, and checking execution with
ltrace, I observed malloc is called 1871 times when free is just called
922 times.
Isn't it an issue?
Please keep in mind that perl's memory allocation strategy in general is
optimized for longer running programs, not for one-off scripts (which
makes sense, since one-off scripts don't usually need the performance
gains). This means that for instance subroutines will get memory
allocated on the assumption that they'll be called again, and will take
about as much memory the next time.
This is NOT a memory leak per se, but it does mean that if you have a
subroutine that takes 100Mb to complete, your program will take that
memory and probably not give it back until the program ends. IOW, if you
have a long-running program that only means you need 100Mb for it to
run, it does NOT mean it takes a 100Mb for each call.
In your test case, don't assume that just because the regular expression
replacements don't in theory *need* to use any additional RAM, they
won't. Especially not if you're using UTF-8 encoded strings (which you
are). Perl algorithms tend to exchange RAM for speed in most cases
anyway, and replacing a match with a new string of exactly the same
length in bytes in a unicode string is a pretty uncommon use-case, so
it's likely not optimized.
Anyway, I've not seen a serious memory leak in perl itself in ages, and
I run perl processes that use up to 8 Gb of RAM and run for months
without issues.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
.
- Follow-Ups:
- Re: Memory issues
- From: Peter J. Holzer
- Re: Memory issues
- From: jm
- Re: Memory issues
- 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
- Re: Memory issues
- From: jm
- Memory issues
- Prev by Date: Re: Memory issues
- Next by Date: Re: BEGIN, INIT etc...
- Previous by thread: Re: Memory issues
- Next by thread: Re: Memory issues
- Index(es):
Relevant Pages
|