Re: PHP Memory issues in PHP5 as well?

From: Date: Thu, 25 May 2006 22:12:47 +0000
Subject: Re: PHP Memory issues in PHP5 as well?
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6946@lists.php.net to get a copy of this message
I have noticed that when unreferencing data in PHP that the memory usage of PHP does not shrink. I only noticed this because I was dealing with some 40mb txt files, and to memory usage would suddenly jump to 70mb, and when I freed the array would not decrease, but when that function was called again, that app still only stayed at 70mb. So from what I see. It's not all bad. It's not all good. Karl On 5/25/06, Benjamin Smith <lists@benjamindsmith.com> wrote:
I have a fairly large codebase that will have to be majorly refactored switching from PHP4/GTK1 to PHP5/GTK2. I've been considering this as an opportunity to pay down on some technological debt, and make more use of classes rather than our current layout of "lots of functions" with GTK widgets saved in a globally accessed array. But, based on this thread, that may well turn out to be a very bad idea, leading to stability problems. Are these memory issues (not freeing memory when allocated inside a function or PHP class object) also present in PHP5? Can anybody confirm that unref() solves the problem that unset() does not? Also, does anybody have any script that consistently reproduces the problem? I wrote the following to see if I could reproduce this memory bug, and it didn't have any problem with PHP4 on Fedora Core 3: ############################################ set_time_limit(0); Function SuckupRam()
        {
        $student=array();
        for ($i=0; $i<10000; $i++)
                $student[]='asdfasdfasdfasdfasdfasdfasdfasdf';
        return true;
        }
while (true)
        SuckUpRam();
############################################ Run for several minutes, this script used up 0.2% of system RAM. Tried again, this time with random variable names: ############################################ set_time_limit(0); Function RandomChar($length=0)
        {
        $min=ord('A');
        $max=ord('z');
        if (!$length)
                $length=rand(1, 50);
        $return='';
        for ($i=0; $i<$length; $i++)
                {
                $return.=chr(rand($min, $max));
                }
        return $return;
        }
Function SuckupRam()
        {
        $var=RandomChar();
        ${$var}=array();
        for ($i=0; $i<10000; $i++)
                ${$var}[]='asdfasdfasdfasdfasdfasdfasdfasdf';
        return true;
        }
while (true)
        SuckUpRam();
############################################# Same result. Where is this memory leak an issue? Has anyone confirmed that this is a language issue and not a bug in the PHP script? -Ben -- "The best way to predict the future is to invent it." - XEROX PARC slogan, circa 1978 -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.gtk.general (#6946) next »