This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Perl bug?

> Hi,
> consider the following statement:
>  $a = "a" x (100 * 1024 * 1024)
> When you create a script which does this over and over again, you'll
> observe a strange memory problem.

Can you show your script?

> By stracing I found that for each of these statements the following
> happens:
>  "a"         --> malloc (2 bytes)
>  x 100 Megs  --> realloc (100 Megs) + malloc (100 Megs)
> So the result is that each string of 100 Megs requires 200 Megs of
> memory.  Doing this once is no problem, but doing it over and over
> again will hit the maximum memory available twice as early.

This is as I would expect.  Most operators have a target, a temporary
lexical, allocated to store their results.  Like all lexicals, these
hold on to any memory they have allocated in the hope of saving having
to allocate it a second time.

> I can only assume that either the garbage collector doesn't kick in when
> it should, or the garbage collector doesn't even know about this wasted
> memory, which would be a generic memory leak either way.  However, it's
> not clear if this depends on the Perl version, or if it depends on the
> 64 bit int setting when building Perl.

I'd more likely suspect differences in the usemymalloc setting (perl
-V:usemymalloc).  I'm not clear on exactly what you are seeing; again,
I'd like to see your test script.

I'm looking for a job:

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]