| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2008-06-18 09:12 UTC] louis at steelbytes dot com
 Description:
------------
the following code fails with 
  Fatal error: Allowed memory size of 587896 bytes exhausted (tried to allocate 262145 bytes)
command:
  php.exe -n -f memuse.php
memuse.php:
  @ob_end_flush();
  @ob_implicit_flush(1);
  define('big_size',256*1024);
  define('saftey',4*1024);
  ini_set('memory_limit',memory_get_usage()+big_size*2+saftey);
  $big = str_repeat('x',big_size);
yet if I change big_size to 1024*1024, then it works?
and a simlar script
  @ob_end_flush();
  @ob_implicit_flush(1);
  define('big_size',200*1024);
  define('saftey',4*1024);
  ini_set('memory_limit',memory_get_usage()+big_size+saftey);
  echo str_repeat('x',big_size);
also fails, yet if I change big_size to 180*1024 then it works?
PS, note that in the first script I set mem limit to 2 times big_size, and in the 2nd script I did not.
Reproduce code:
---------------
see above
Expected result:
----------------
see above
Actual result:
--------------
see above
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 05:00:01 2025 UTC | 
> but this is not a bug what is it then? why can't I use memory_get_usage() + ini_set('memory_limit',xxx) to check for memory leaks in my code? do I just give up and ini_set('memory_limit',4GigaBytes) and never give a damn about memeory?