ID: 50111
Updated by: [email protected]
Reported By: [email protected]
Status: Feedback
Bug Type: Streams related
Operating System: Linux
PHP Version: 5.2.11
New Comment:
Test code changed to (added the unset() statement):
$m0 = $m1 = $i = 0;
$c = null;
while ($i<5) {
$m0 = memory_get_usage();
$c = stream_context_create();
unset($c);
$m1 = memory_get_usage();
echo $m1-$m0,PHP_EOL;
++$i;
}
Output:
336
420
420
420
420
Though, as a language feature I would assume that in the second
iteration the memory occupied by the previous assignment would be freed
implicitly. Is that a wrong assumption?
Previous Comments:
------------------------------------------------------------------------
[2009-11-08 21:17:53] [email protected]
hmmm.. not sure, why u think there is a leak.
when u write this below code
$c = stream_context_create();
u do understand that underlying php engine need to do some processing
underneath and store the reference of this processing in $c variable.
this does require some memory consumption.
i guess, if u do some thing like and still no
$c = stream_context_create..
unset($c);
$m1 = memory_get_usage();
and still see memory leak , then let us know..
------------------------------------------------------------------------
[2009-11-08 01:06:54] [email protected]
Code to reproduce can be made simpler, since the problem seems to be
with stream_context_create():
$m0 = $m1 = $i = 0;
$c = null;
while ($i<5) {
$m0 = memory_get_usage();
$c = stream_context_create();
$m1 = memory_get_usage();
echo $m1-$m0,PHP_EOL;
++$i;
}
------------------------------------------------------------------------
[2009-11-07 09:26:05] [email protected]
Description:
------------
When stream_context_create() is used in conjunction with
file_get_contents() or other stream related functions that accept a
context parameter, memory is being leaked.
Reproduce code:
---------------
for ($i=0;$i<5;++$i){
$m0 = memory_get_usage();
file_get_contents('http://www.google.com', false,
stream_context_create(array()));
$m1 = memory_get_usage();
echo $m1-$m0,PHP_EOL;
}
Expected result:
----------------
X (where X is the memory increase for the first iterator)
0
0
0
0
Actual result:
--------------
X (where X is the memory increase for the first iterator)
384 (or something similar)
420
420
480
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50111&edit=1