Re: Memory profiler for PHP?

From: Date: Thu, 31 May 2007 07:44:08 +0000
Subject: Re: Memory profiler for PHP?
References: 1 2 3 4  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-7893@lists.php.net to get a copy of this message
> Now the real test: > I create a dialog and after I call destroy() manually and then I unset the > object. > I do this repeatedly and memory usage keeps increasing. > So neither destroy() frees the memory. > > There is propably some refference of some object which is not dying. > How can I ensure that there are no child widgets somewhere in my hierarchy > that are still refferenced ? > Got it, I removed everything until I've seen what it is. But it seems like a memory leak of GtkTreeViewColumn::set_sort_column_id() rather than a GtkDialog bug. GtkDialog itself and it's subclass does not seam to leak memory. Here is a minimal code to produce the leak. If I reopen the dialog continously I notice about 100kB of memory increasing for every 20-30 dialogs. Commenting out the $column->set_sort_column_id(0) solves the problem. #!/usr/bin/php <?php if( !class_exists('gtk')) { dl('php_gtk2.so'); ini_set('php-gtk.codepage','utf8'); } class MyDialogTest extends GtkDialog { private $controller; public function __construct($parent, $title, $label) { parent::__construct($title, $parent, Gtk::DIALOG_MODAL | Gtk::DIALOG_DESTROY_WITH_PARENT, array('Click to Close', Gtk::RESPONSE_OK)); $treeview = new GtkTreeView(); $scroll = new GtkScrolledWindow(); $scroll->add($treeview); $this->vbox->pack_start($scroll); $model = new GtkTreeStore(Gtk::TYPE_STRING); $treeview->set_model($model); $cellRenderer = new GtkCellRendererText(); $column = new GtkTreeViewColumn('col.0', $cellRenderer, 'text', 0); $column->set_sort_column_id(0); //this consumes memory $treeview->append_column($column); $buttons = $this->action_area->get_children(); $buttons[0]->grab_focus(); } function __destruct() { echo "destroyed (derived object)\n"; //parent::__destruct(); //if called causes an error } } $wnd = new GtkWindow(); $wnd->set_title('Memory leak'); $wnd->connect_simple('destroy', array('gtk', 'main_quit')); $btnDlg = new GtkButton('Show dialog'); $btnDlg->connect_simple('clicked', 'showDlg'); $wnd->add($btnDlg); $wnd->show_all(); function showDlg() { GLOBAL $wnd; $dlg = new MyDialogTest($wnd, 'My Dialog', 'click me'); $dlg->show_all(); $dlg->run(); $dlg->destroy(); unset($dlg); } gtk::main(); ?>

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