|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2011-12-20 05:20 UTC] roberto at spadim dot com dot br
 Description:
------------
hi, when i create a context inside a function i see a memory leak, but when i create it in the main source code line, i don´t see it...
please check the script..
i think the problem is something that don´t leave memory get back when destroying context variable
Test script:
---------------
memory leak:
<?php
function g(){
        $context=stream_context_create(array('http'=>array('timeout'=>1)));
        $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
        unset($context);
        return($ret);
}
        $base=memory_get_usage();
        while(1){
                g();
                usleep(50000);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger here....
        }
?>
memory leak too:
<?php
        $base=memory_get_usage();
        while(1){
                $context= stream_context_create(array('http'=>array('timeout'=>1)));
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret,$context);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger...
        }
?>
nice:
<?php
        $base=memory_get_usage();
        $context= stream_context_create(array('http'=>array('timeout'=>1)));
        while(1){
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret);
                echo    (memory_get_usage()-$base)."\n";
// memory is nice here...
        }
?>
Expected result:
----------------
NICE:
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...
42568
Warning...
43792
Actual result:
--------------
well i think that others fields explain...
MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...
(+- 1224 per while interaction)
i don´t know how to solve this, unset don´t work, =null don´t work, and i don´t find a function to destroy contexts...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 12:00:01 2025 UTC | 
maybe the array parameters isn´t being removed from memory? i tryed to change code inserting a comma after timeout parameter "'timeout'=>1," and it add more memory leak per interaction more commas = more memory leak $context= stream_context_create(array('http'=>array('timeout'=>1,,,,,)));