php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66372 Garbage collection issue
Submitted: 2013-12-31 07:35 UTC Modified: 2014-01-01 18:57 UTC
From: nikcomestotalk at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.23 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikcomestotalk at gmail dot com
New email:
PHP Version: OS:

 

 [2013-12-31 07:35 UTC] nikcomestotalk at gmail dot com
Description:
------------
Memory getting exhausted when a php script[staticarray.php] is included multiple times.

staticarray.php size is 221K and which contain only arrays

Example

memcheck.php[Code shown in test script]

When i simply execute this
 02.75 mb
 12.75 mb
 22.75 mb
 32.75 mb
 42.75 mb
 52.75 mb
 62.75 mb
 72.75 mb
 82.75 mb
 92.75 mb
 102.75 mb


I have used include_once, still memory usage keeps getting up. 

Steps i had taken to stop memory usage, but went in vain
1. use gc_enable
2. put unset(Variable name) above every array creation




Test script:
---------------
//Memcheck.php
<?php
for($i=0;$i<10;$i++)
{
        include_once("staticarray.php");
        echo "\n $i". convert(memory_get_usage(true));
}
$CITY_DROP=array();
        echo "\n $i". convert(memory_get_usage(true));

function convert($size)
 {
    $unit=array('b','kb','mb','gb','tb','pb');
    return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
 }

?>


Expected result:
----------------
I expect memory usage should be same throughout.
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb
 02.75 mb

Actual result:
--------------
 02.75 mb
 12.75 mb
 22.75 mb
 32.75 mb
 42.75 mb
 52.75 mb
 62.75 mb
 72.75 mb
 82.75 mb
 92.75 mb
 102.75 mb

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-12-31 08:24 UTC] krakjoe@php.net
-Status: Open +Status: Feedback
 [2013-12-31 08:24 UTC] krakjoe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2013-12-31 08:42 UTC] nikcomestotalk at gmail dot com
-Status: Feedback +Status: Open
 [2013-12-31 08:42 UTC] nikcomestotalk at gmail dot com
testscript has already been added Memcheck.php

staticarray.php[Data is too huge, so adding few arrays to script][And i can't share the real data, some legal issues]
<?php
$siteType=array("API","MOBILE","WEB","ANDROIDAPP","IOSAPP");
$siteServer=array("127.0.0.1","127.0.0.2","127.0.0.3","127.0.0.4");
$country=array("INDIA","AUSTRALIA","UK","USA","CHINA","JAPAN");
?>
 [2014-01-01 08:36 UTC] krakjoe@php.net
-Status: Open +Status: Feedback
 [2014-01-01 08:36 UTC] krakjoe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

We require the inclusion of (by means of a link to some online hosting service for text files, ie git/pastebin etc) code that reproduces the error you experience.

We have no way to guess the content of staticarray.php, and 3 arrays is not enough, obviously. If you are not able to include some data then generate some that exhibits the same symptoms, but generate it in such a way that it's as close to your use case as possible.
 [2014-01-01 15:31 UTC] nikcomestotalk at gmail dot com
-Status: Feedback +Status: Open
 [2014-01-01 15:31 UTC] nikcomestotalk at gmail dot com
Files added to github

https://github.com/nikcomestotalk/memcheck

staticarray.php is being generated with random data and it's close to what use case i specified.
 [2014-01-01 18:57 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2014-01-01 18:57 UTC] krakjoe@php.net
If the code is sane, the result is sane.

Using include_once inside a function scope resulting in the manipulation of an array in the global scope of another file but still inside the function scope and creating no usable reference to that array is what causes perceived strangeness.

https://github.com/krakjoe/memcheck

#0      524288.000/524288.000 Kb        1000
#1      524288.000/524288.000 Kb        1000
#2      524288.000/524288.000 Kb        1000
#3      524288.000/524288.000 Kb        1000
#4      524288.000/524288.000 Kb        1000
#5      524288.000/524288.000 Kb        1000
#6      524288.000/524288.000 Kb        1000
#7      524288.000/524288.000 Kb        1000
#8      524288.000/524288.000 Kb        1000
#9      524288.000/524288.000 Kb        1000
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC