Re: PHP Memory issues

From: Date: Mon, 22 May 2006 21:52:55 +0000
Subject: Re: PHP Memory issues
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-6935@lists.php.net to get a copy of this message
Variables assigned inside functions are not freed until the script ends not after the function is called and returns as expected. Set up all the variables you need globally so you can reuse them and your memory problems should go away. HTH On Mon, 22 May 2006, 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(); > ?> > > -- a8888b. Brian A. Stumm d888888b. bs@bs-linux.com 8P"YP"Y88 http://www.bs-linux.com 8|o||o|88 The Choice of a Gnu Generation 8' .88 8`._.' Y8. # d/ `8b. #### ### .dP . Y8b. ## # d8:' " `::88b. ## ### ### ### ### ### ### ### d8" `Y88b ## # ## ### ## ## ## ## ## :8P ' :888 ## # ## ## ## ## ## ### 8a. : _a88P ## ### ## ## ## ## ### ._/"Yaa_ : .| 88P| ## # ### ## ## ## ## ## ## \ YP" | 8P . ## ## ### # ## ## ### ### ## ## / \._____.d| .' ######### ### #### #### ### ### ### ### --..__)888888P._.'

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