php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36924 string concat
Submitted: 2006-03-30 15:54 UTC Modified: 2006-03-30 16:44 UTC
From: arnout at argeweb dot nl Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: FreeBSD 5.4-RELEASE-p11
Private report: No CVE-ID: None
 [2006-03-30 15:54 UTC] arnout at argeweb dot nl
Description:
------------
Using the following code leaks 32 bytes of memory.

$doe = 'yoyoyo';
echo "john $doe";



PHP 5.1.2 (cli) (built: Feb 22 2006 16:17:32)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
    with Zend Extension Manager v1.0.10, Copyright (c) 2003-2006, by Zend Technologies
    with Zend Optimizer v3.0.0-Beta2, Copyright (c) 1998-2006, by Zend Technologies


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

@ob_end_flush(); // to be sure


function fake1( $string ){
	echo "kaas ".$string;
}

function fake2( $string ){
	echo "kaas $string";
}

function fake3( $string ){
	$string = "kaas $string";
}

function fake4( $string ){
	echo "kaas $string asdf";
}


echo "<P><b>function fake1</b></p>";

for( $i = 0;$i < 10; $i++ ){
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
	fake1( "string" );
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}

echo "<P><b>function fake2</b></p>";

for( $i = 0;$i < 10; $i++ ){
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
	fake2( "string" );
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}

echo "<P><b>function fake3</b></p>";

for( $i = 0;$i < 10; $i++ ){
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
	fake3( "string" );
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}

echo "<P><b>function fake4</b></p>";

for( $i = 0;$i < 10; $i++ ){
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
	fake4( "string" );
	echo "Memory at ".$i.": ".memory_get_usage()."<Br>\n";
}


?>

Expected result:
----------------
Hardly any change in memory usage.

Actual result:
--------------
function fake1
Memory at 0: 42920
kaas stringMemory at 0: 42984
Memory at 1: 42984
kaas stringMemory at 1: 42984
Memory at 2: 42984
kaas stringMemory at 2: 42984
Memory at 3: 42984
kaas stringMemory at 3: 42984
...etcetera... +64 bytes, only once.

function fake2
Memory at 0: 42984
kaas stringMemory at 0: 43000
Memory at 1: 43000
kaas stringMemory at 1: 43016
Memory at 2: 43016
kaas stringMemory at 2: 43032
Memory at 3: 43032
kaas stringMemory at 3: 43048
...etcetera... +16 bytes

function fake3
Memory at 0: 43144
Memory at 0: 43160
Memory at 1: 43160
Memory at 1: 43176
Memory at 2: 43176
Memory at 2: 43192
Memory at 3: 43192
Memory at 3: 43208
...etcetera... +16 bytes

function fake4
Memory at 0: 43304
kaas string asdfMemory at 0: 43328
Memory at 1: 43328
kaas string asdfMemory at 1: 43352
Memory at 2: 43352
kaas string asdfMemory at 2: 43376
...etcetera... +24 bytes

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-30 15:56 UTC] arnout at argeweb dot nl
"Using the following code leaks 32 bytes of memory."

Cleaning up the demo-script while submitting this bug gave a clearer image. The demo says it all.
Using unset() didn't change anything anywhere by the way.
 [2006-03-30 16:07 UTC] tony2001@php.net
Leaks are reported by the engine.
What you see is the way the engine works and this is not a bug/leak.
 [2006-03-30 16:44 UTC] arnout at argeweb dot nl
OK, I guess it's not a memory leak then.
But nevermind the name: This problem makes it impossible to write a long running script, because it keeps growing until it dies of memory shortage.

Is this suicide designed, or is it a bug?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC