Note that there are some explanatory texts on larger screens.

plurals
  1. POpython memory leak using wxPython
    text
    copied!<p>I recently realised, that my program have a memory leak, it's small, but either, I think it shouldn't be there at all.</p> <p>Part which causes memory leak actually creates a new <code>wx.Panel</code> and add's it to interface using <code>wx.WindowSplitter</code> and then removes panel and un splits window.</p> <pre><code>self.getAction(self, event): if self.lastEdit[0] != None: if self.lastEdit[4] == STATEMENT: dialog = EditStatement(self.API.editorSplitter, self.API, self.lastEdit, self.statementUpdateClbk) elif self.lastEdit[4] == CONDITION: dialog = EditCondition(self.API.editorSplitter, self.API, self.lastEdit, self.conditionUpdateClbk) # Show or hide split window self.splitEditor(dialog) def splitEditor(self, editPanel): self.API.editorSplitter.Unsplit() if self.lastPanel != None: self.lastPanel.DissociateHandle() self.lastPanel.DestroyChildren() self.lastPanel.Destroy() self.lastPanel = editPanel if editPanel != None: self.API.editorSplitter.SplitVertically(self.API.tabManager, editPanel, -305) </code></pre> <p>Note that <code>EditStatement</code> un <code>EditCondition</code> is <code>wx.Panel</code> clases mentioned before. Calling <code>getAction()</code> in cycle randomly increases memory usage, the weirdest thing is, that at some iterations there is no change, at some iterations used memory even falls a bit, but at most iterations used memory grows. Here is some output of debug, made using <code>gc</code> module wrapper.</p> <p>Used code to test:</p> <pre><code>def cycler(self): while True: self.getAction(None) #Show window wx.YieldIfNeeded() self.mem() # prints memory information self.splitEditor(None) #Hide window wx.YieldIfNeeded() self.mem() # prints memory information </code></pre> <p>Output is as follows: </p> <blockquote> <pre><code>Window action - Action Object Count Create Window - Added StaticText 10 Create Window - Changed dict +1 Create Window - Added GridBagSizer 1 Create Window - Changed list +2 Create Window - Added CheckBox 4 Create Window - Changed ComboBox +6 Create Window - Added EditStatement 1 Create Window - Changed BoxSizer +1 Create Window - Changed instancemethod +15 Create Window - Count = 25453 Create Window - Memory(rss): 42528 Destroy Window - Changed dict -1 Destroy Window - Changed list -2 Destroy Window - Changed ComboBox -6 Destroy Window - Changed BoxSizer -1 Destroy Window - Changed instancemethod -15 Destroy Window - Deleted StaticText 10 Destroy Window - Deleted GridBagSizer 1 Destroy Window - Deleted CheckBox 4 Destroy Window - Deleted EditStatement 1 Destroy Window - Count = 25412 Destroy Window - Memory(rss): 42528 Create Window - Added StaticText 10 Create Window - Changed dict +1 Create Window - Added GridBagSizer 1 Create Window - Changed list +2 Create Window - Added CheckBox 4 Create Window - Changed ComboBox +6 Create Window - Added EditStatement 1 Create Window - Changed BoxSizer +1 Create Window - Changed instancemethod +15 Create Window - Count = 25453 Create Window - Memory(rss): 42536 Destroy Window - Changed dict -1 Destroy Window - Changed list -2 Destroy Window - Changed ComboBox -6 Destroy Window - Changed BoxSizer -1 Destroy Window - Changed instancemethod -15 Destroy Window - Deleted StaticText 10 Destroy Window - Deleted GridBagSizer 1 Destroy Window - Deleted CheckBox 4 Destroy Window - Deleted EditStatement 1 Destroy Window - Count = 25412 Destroy Window - Memory(rss): 42540 Create Window - Added StaticText 10 Create Window - Changed dict +1 Create Window - Added GridBagSizer 1 Create Window - Changed list +2 Create Window - Added CheckBox 4 Create Window - Changed ComboBox +6 Create Window - Added EditStatement 1 Create Window - Changed BoxSizer +1 Create Window - Changed instancemethod +15 Create Window - Count = 25453 Create Window - Memory(rss): 42552 Destroy Window - Changed dict -1 Destroy Window - Changed list -2 Destroy Window - Changed ComboBox -6 Destroy Window - Changed BoxSizer -1 Destroy Window - Changed instancemethod -15 Destroy Window - Deleted StaticText 10 Destroy Window - Deleted GridBagSizer 1 Destroy Window - Deleted CheckBox 4 Destroy Window - Deleted EditStatement 1 Destroy Window - Count = 25412 Destroy Window - Memory(rss): 42556 Create Window - Added StaticText 10 Create Window - Changed dict +1 Create Window - Added GridBagSizer 1 Create Window - Changed list +2 Create Window - Added CheckBox 4 Create Window - Changed ComboBox +6 Create Window - Added EditStatement 1 Create Window - Changed BoxSizer +1 Create Window - Changed instancemethod +15 Create Window - Count = 25453 Create Window - Memory(rss): 42576 </code></pre> </blockquote> <p>As You can see, used memory is increasing, but object count doesn't change after creation and deletion, I just don't understand what possibly can create such a memory leak. Any Ideas would be appreciated. In 45 minutes memory usage had grown from <code>~ 20 MB</code> to <code>~ 500 MB</code>. </p> <p>P.S. If anyone is interested, source code of created Panels can be found at: <a href="https://code.google.com/p/mansos/source/browse/trunk/tools/IDE/src/edit_statement.py" rel="nofollow">EditStatement</a> <a href="https://code.google.com/p/mansos/source/browse/trunk/tools/IDE/src/edit_condition.py" rel="nofollow">EditCondition</a></p> <p>P.S.S. I'm not sure, but I tend to think it's wx.Python bug, something with <code>wx.SplitterWindow</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload