php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53031 GC does not collect before PHP issue "Allowed memory size exhausted"
Submitted: 2010-10-09 16:50 UTC Modified: 2010-10-09 18:20 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: an0nym at narod dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.3 OS: Windows Server 2008 R2 x64
Private report: No CVE-ID: None
 [2010-10-09 16:50 UTC] an0nym at narod dot ru
Description:
------------
GC does not collect cycles before PHP issue "Allowed memory size exhausted", 
therefore it is possible for a script to get this error even if GC is enabled and 
there is enough memory to reuse. 

To get error the script just has to fill all the remaining memory after last GC 
and before next, fill no matter how: with garbage or normal info. 

It is obvious for me, that calling GC before issuing error is a must have, as a 
last possibility to continue normal execution. 

Test script:
---------------
<?php
set_time_limit(0);
error_reporting(PHP_INT_MAX);
ini_set("memory_limit", "2M");

echo memory_get_peak_usage(true), "\r\n";

$o1 = new StdClass();
$o2 = new StdClass();
$o1->v1 = $o2;
$o1->v2 = $o1;
$o1->v = str_repeat("a", 1024 * 1024);
unset($o1, $o2);
echo memory_get_peak_usage(true), "\r\n";

$o1 = new StdClass();
$o2 = new StdClass();
$o1->v1 = $o2;
$o1->v2 = $o1;
$o1->v = str_repeat("a", 1024 * 1024);
unset($o1, $o2);
echo memory_get_peak_usage(true), "\r\n";

Expected result:
----------------
I expect to see the same result as if I run 

<?php
...
echo memory_get_peak_usage(true), "\r\n";

$o1 = new StdClass();
$o2 = new StdClass();
$o1->v1 = $o2;
$o1->v2 = $o1;
gc_collect_cycles();
$o1->v = str_repeat("a", 1024 * 1024);
unset($o1, $o2);
echo memory_get_peak_usage(true), "\r\n";

Actual result:
--------------
PHP Fatal error:  Allowed memory size of * bytes exhausted (tried to allocate * 
bytes)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-09 18:02 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-10-09 18:02 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Check the documentation which describes when cycles are collected: http://de3.php.net/manual/en/features.gc.collecting-cycles.php This won't change.
 [2010-10-09 18:20 UTC] an0nym at narod dot ru
-Type: Bug +Type: Feature/Change Request
 [2010-10-09 18:20 UTC] an0nym at narod dot ru
PHP can reuse memory, but doesn't do this. If this isn't a bug (that I'm not agree with), then this is surely a feature request.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 14:01:33 2024 UTC