ID:               44069
 Updated by:       [EMAIL PROTECTED]
-Summary:          Huge memory usage with concatenation using . instead
                   of .=
 Reported By:      frode dot guldberg at exense dot com
-Status:           Assigned
+Status:           Closed
 Bug Type:         Performance problem
 Operating System: *
 PHP Version:      5.2.5
 Assigned To:      dmitry
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2008-02-13 18:25:44] [EMAIL PROTECTED]

Dmitry, can you check this out please? The example script kills my
machine totally if I don't use the .= :)

------------------------------------------------------------------------

[2008-02-07 13:39:05] frode dot guldberg at exense dot com

Description:
------------
In a for-loop I concatenate two strings. If I at the same time fill a
relatively small array, I get a huge memory consumption. This only
happens if I concatenate the two strings using '.'. If I use '.=' the
memory usage is as expected.

Reproduce code:
---------------
<?php

$string = str_repeat('This is a teststring.', 50);

echo 'Length: '.strlen($string).'<br>';
echo 'Memory Before:'.memory_get_usage(true).'<br>';

for($i = 1; $i <= 2000; $i++)
{
//      $newstring .= $string; //This uses an expected amount of mem.
        $newstring = $newstring . $string; //This uses very much mem.

        for($j = 1; $j <= 10; $j++)
        {
                $array[] = 'test';
        }
}
echo 'Memory After:'.memory_get_usage(true).'<br>';
echo 'Total Length of String: '.strlen($newstring).'<br>';

?>

Expected result:
----------------
Length: 1050
Before:262144
After:4456448
Length: 2100000


Actual result:
--------------
Length: 1050
Before:262144
After:161742848
Length: 2100000


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44069&edit=1

Reply via email to