Re: Memory issues
| From: | Gonzalo Monzón | Date: | Mon, 13 Dec 2004 06:08:01 +0000 |
| Subject: | Re: Memory issues | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5346@lists.php.net to get a copy of this message | ||
Nghia wrote:
Hi, Does anyone know how memory allocation/deallocation work with PHP-GTK? It seems that the memory usuage just keeps increasing even when I'm sure I've freed up memory via destroy() on the widgets. This happens on a Windows 98/XP machine. Heres a really simple example <?php if (!extension_loaded('gtk')) dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); function button_press() { $dialog = &new GtkDialog(); $dialog->show_all(); $dialog->destroy(); } $window = &new GtkWindow(); $button = &new GtkButton("Dialog"); $button->connect('clicked', 'button_press'); $window->add($button); $window->show_all(); Gtk::main(); ?> Just keep clicking the button and the memory will start to increase rather than remain constant as I would expect. Nghia Hi to all,I'd like to share some suggestions... this is a test made under win32, I dont know exactly how it will perform under linux. First thing: Using nghia code i try opening 1000 dialogs, so it results in consuming 1,4Mb, and I found that if you set to null the container variable for the widgets, in this example you can save plus than 200kb. of memory, if you set to null the container variable once the dialog is destroyed.... Doing a loop to execute 1000 times this function: function button_press() { $this->dialog = &new GtkDialog(); $this->dialog->show_all(); $this->dialog->destroy(); } consumes 212kbytes plus than if you add this line at after the dialog->destroy() : $this->dialog=null; And there's no difference between using function scope variables or class scope ... the memory usages and differences are the same. Now I will tell you the memory overall usage in my system doing this test and too I will explain another strange thing with memory management... the "second thing". I do execute the app from the command line and opens the window. (my base code is taken from the nghia example). As expected. The memory usage now is
php.exe 11,172 kb.Second thing: And that strange thing I was saying is this: if do I click on the task-bar to get back to the command line window, the memory usage drops to 120kb... and this behaviour I think is very strange..., i've seen the same thing on some big php-gtk apps, and they fall from 40 or 50 Mb of memory usage to 2 or 3MB but everything seems to continue working well... Anyway what I was talking about: I connected the button_press signal from the dialog to run 1000 times the function shown before, and when adding the last line after the loop
the mem. usage is 12,668Kb, or if you don't reset the "widget" to null, it ends with 12,880kb...So running 1000 times the function results in a 1,4kb. of memory waste per "dialog" of the test... (1,4Mb) and if you open the command line so you release or release + minimize + release again, it falls to 120kb memory usage only... really light! ... one click later (so 1000 dialogs more are instantiated and destroyed) the mem. usage is 4,064Kb... Is this really the expected behaviour (I mean about the memory falls when opening command line), or maybe is this something "normal" within php4 - gtk1 ??? I don't know if this happen with non-gtk php - cli - apps too ... ??? Does this happen too under linux? Gonzalo Monzón