Re: PHP Memory issues

From: Date: Mon, 22 May 2006 23:01:38 +0000
Subject: Re: PHP Memory issues
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6936@lists.php.net to get a copy of this message
Andrew - I've been fighting this issue off and on for some time, w/o a lot of definitive conclusions. I am hoping for a better life in PHP-Gtk2. Something we have seen is that the leak behaves a lot differently depending on the OS. We've had minimal problems w/ any of the NT's, and a host of ones on Win98. Also, with a nod to Brian, all of our variables are global, and that doesn't appear to make much of a difference, maybe because of the size of our app. One thing I've come across recently was another developer's suggestion that setting a variable to NULL (as in: $somevar = NULL), actually released memory vs unset which, I agree, doesn't appear to do that at all. I haven't had a chance to play with this yet, so I can't say one way or the other if it works.... If you do try it, let us know if it makes a difference. Madeleine D. Andrew Buczacki wrote:
I'm working on an app and recently I've noticed that there are substantial memory leaks no matter how I maneuver in the program. It almost seems that the memory isn't being freed by PHP when variables are no longer referenced or moved out of scope. I included a sandbox program that mildly resembles my app and the problem remains. I was wondering if someone who has experience with PHP memory allocation/management could take a look at my dummy code and find a solution to this issue. I recently found out about unset() and have been fiddling around with it, but it doesn't seem to free up the memory. <?php if (!extension_loaded('gtk')) { dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); } class Page1 extends GtkLabel{ var $ary; function Page1() { $this->ary = array(); for($i=0;$i<1000;$i++) $this->ary[$i]=4242424242; $this->GtkLabel("This is Page 1"); } } class Page0 extends GtkLabel{ var $ary; function Page0() { $this->ary = array(); for($i=0;$i<1000;$i++) $this->ary[$i]=4242424242; $this->GtkLabel("This is Page 0"); } } class stupidobject { var $currPage; var $win; var $box; var $button; function stupidobject() { $this->currPage=0; $this->win = &new GtkWindow(); $this->button = &new GtkButton("Toggle"); $this->box = &new GtkHBox(); $vbox = &new GtkVBox(); $vbox->pack_start($this->box); $vbox->pack_start($this->button); $startlabel = &new GtkLabel("Start"); $this->box->pack_start($startlabel); $this->button->connect("clicked", array($this, "toggle"));
//    $this->button->connect("clicked", "toggle", $this);
$this->win->add($vbox); $this->win->show_all(); } function toggle() { if($this->currPage == 1) $this->currPage = 0; else $this->currPage = 1; eval('$temp = &new Page'.$this->currPage.'();'); $child = $this->box->children(); //print_r($this->box); // print_r($child[0]); $this->box->remove($child[0]); unset($child[0]); // print_r($child[0]); //print_r($this->box); $this->box->pack_start($temp); $this->box->show_all(); } } $bob = &new stupidobject(); gtk::main(); ?>


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