Il giorno lun, 11/04/2011 alle 18.20 +0000, Hakan K ha scritto:
> 
> Same behavior with "gtk.glade.XML" object, not only gtk.Builder.
> 
> in attachment, there is a simple window that containing a button. When
> pushes button, it creates a dialog box. When ok button of dialog
> pushes, dialog get destyoyed. 
> 
> problem: approximate every 30 shows of dialog consumes 0.1 Kb of
> memory(linux says it resident memory). 
> is it normal or what is wrong with this code?

As Laszlo told you, you can probably call it "bug", but that's such a
minor bug that it's probably not even worth the effort of reporting.

The wrong thing with your code is that you need to show many times the
same window, and instead than hide()ing and show()ing it every time,
each time you recreate a gtk.glade.XML, retrieve from it the
messagedialog, and finally destroy it.
The smart way is: you have n XML definitions? You'll probably create
only (at most) n gtk.Builder() instances in the course of all the
running time of your app.
> 


> in my previous sample code, i tested code for about 1 hour. Memory
> usage reaches 60 Mb and growing continously.

60 Mb = 18 000 000 messagedialogs open/closed, right?
Or if you prefer, if an user spends 1 month in front of your app,
opening on average 1 messagedialog every 10 seconds, he will have wasted
slightly less than 1 Mb, right?

I admit in an app of mine I'm doing exactly what I suggested to avoid
above, and I guess I still won't loose my sleep tonight.

Pietro

> Please note, memory usage doesn't growing when widgets created with
> code and "gtk.glade.XML" or "gtk.Builder" not used.
> 
> 
> 
> 
> 
> ______________________________________________________________________
> From: [email protected]
> To: [email protected]
> Date: Fri, 8 Apr 2011 16:47:04 +0000
> Subject: [pygtk] gtk.Builder and memory leak...
> 
> 
> Hi everyone,
> 
> i am learning and writing a pygtk aplication. i have a problem with
> gtk.builder.
> there is very small part of my application code in attachment, for
> test purpose and debugging.
> 
> problem is: 
>   i think, gtk.builder object doesn't destroy completely when owner
> instance destroyed. This causes memory leak. in "system
> monitor" (ubuntu/linux) memory usage growing every time of window
> creation nearly 0.1 kb. (startup memory around 6.3 mb and it exceeds
> 10 mb in minutes and growing)
> 
> small explain for code:
>    xTimer instance starting timeout every five secs. on every timer
> event, new window creating and displaying. window destroy itself in 2
> seconds. but it seems to gtk.builder instance of window remains memory
> and causes memory leak.
> 
> * when i disable using gtk.builder and create window with code, no
> memory leaks.
> * when i using using gtk.builder and not calling
> "self.builder.connect_signals(self)", no memory leaks .
> 
> * using ubuntu linux 10.10.   python version 2.6.6
> python-gtk2-dev   2.21.0-0ubuntu1
> * i know that if i create window at application start and use
> show/hide method, it will work. But i want to solve and understand
> this problem :)
> 
> Thanks a lot...
> 
> Hakan Kizilhan
> 
> here is code: (also added as attachment)
> 
> -----------main.py-----------------------------------------------------------------
> 
> import gtk, pygtk, gobject
> 
> #builder = gtk.Builder()
> 
> class Display(object):
>     def __init__(self):
>         self.builder = gtk.Builder()
>         self.builder.add_objects_from_file("gui.glade",
> ["Display_Window"])
>                 
>         #get widgets
>   &nbsp ; ;     self.display_window =
> self.builder.get_object("Display_Window")
>         #self.display_window = gtk.Window()
>         self.display_text = self.builder.get_object("Display_Text")
>         self.disable_progress =
> self.builder.get_object("DisableProgress")
>         
>         self.builder.connect_signals(self)
>         
>         #set initials
>         self.timer = None
>         self.progress = 0
>         
>         #timer stuff
>         self.timer = gobject.timeout_add(500, self.on_progress_timer)
>          
>         #set icon
>         pixbuf =
> self.display_window.render_icon(gtk.STOCK_PREFERENCES,
> gtk.ICON_SIZE_MENU)
>         self.display_window.set_icon(pixbuf)
>         #go on
>         self.display_window.show()
>         
>     def on_Display_Window_delete_event(self,widget,data=None):
>     gobject.source_remove(self.timer)        
>     self.display_window.destroy()
>         
>         
>     def on_progress_timer(self): #timing for window destroy
>         seconds = 2
>         self.progress = self.progress + ( (1. / seconds) / 2. )
>         new_val = self.progress
>             
>         if new_val > 1.0:
>             # Do Exit        #new_val = 0.0
>             self.on_Display_Window_delete_event(self)
>             return False
>         # Set the new value
>         print self.progress
>         return True
>     
>     def on_DisableProgress_button_press_event(self, widget, event):
>         #if progressbar clicked, timer will stop
>   &nbsp ; ;     self.progress_paused = True
>         gobject.source_remove(self.timer)
> 
> class xTimer(object):
>     
>     def __init__(self):
>         self.enabled = True
>             
>     def on_time(self):
>         if self.enabled == False : return False 
>         print "OnTime"
>         bb = Display()  # create window
>         
>         return True
>     
>     def start(self):
>         self.enabled = True
>         seconds = 5
>         gobject.timeout _add_seconds(seconds, self.on_time)
>         
>     def stop(self):
>         self.enabled = False
> 
> def main():
>     a = xTimer()
>     a.start()
>     gtk.main()
>     
> if __name__ == '__main__':
>     main()
> 
> 
> -------------gui.glade-----------------------------------------------------------------------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <interface>
>   <requires lib="gtk+" version="2.16"/>
>   <!-- interface-naming-policy toplevel-contextual -->
>   <object class="GtkWindow" id="Display_Window">
>     <property name="width_request">550</property>
>     <property name="height_request">200</property>
>     <property name="window_position">center</pro perty>
>     <signal name="delete_event"
> handler="on_Display_Window_delete_event"/>
>     <child>
>       <object class="GtkVBox" id="vbox1">
>         <property name="visible">True</property>
>         <child>
>           <object class="GtkTextView" id="Display_Text">
>             <property name="height_request">150</property>
>             <property name="visible">True</property>
>             <property name="can_focus">True</property>
>             <property name="editable">False</property& amp; gt;
>             <property name="wrap_mode">word</property>
>           </object>
>           <packing>
>             <property name="position">0</property>
>           </packing>
>         </child>
>         <child>
>           <object class="GtkLabel" id="label1">
>             <property name="height_request">10</property>
>             <property name="visible">True</property>
>       &am p;nb sp;   </object>
>           <packing>
>             <property name="expand">False</property>
>             <property name="fill">False</property>
>             <property name="position">1</property>
>           </packing>
>         </child>
>         <child>
>           <object class="GtkHBox" id="hbox1">
>             <property name="height_request">20</property>
>             <property name="visib le">True</property>
>             <child>
>               <object class="GtkProgressBar" id="DisableProgress">
>                 <property name="width_request">500</property>
>                 <property name="height_request">15</property>
>                 <property name="visible">True</property>
>                 <property name="events">GDK_BUTTON_PRESS_MASK |
> GDK_STRUCTURE_MASK</property>
>                 <si gnal name="button_press_event"
> handler="on_DisableProgress_button_press_event"/>
>               </object>
>               <packing>
>                 <property name="position">0</property>
>               </packing>
>             </child>
>             <child>
>               <placeholder/>
>             </child>
>             <child>
>    &am p;nb sp;          <placeholder/>
>             </child>
>           </object>
>           <packing>
>             <property name="expand">False</property>
>             <property name="fill">False</property>
>             <property name="position">2</property>
>           </packing>
>         </child>
>       </object>
>     </child>
>   </object>
> </interface>
> 
> 
> 
> _______________________________________________ pygtk mailing list
> [email protected] http://www.daa.com.au/mailman/listinfo/pygtk Read the
> PyGTK FAQ: http://faq.pygtk.org/ 
> _______________________________________________
> pygtk mailing list   [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/


_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to