From 95287ef853aac8aa7e369e0d12bf9e4b3a4753fd Mon Sep 17 00:00:00 2001 From: Oliver Gerlich Date: Thu, 26 Sep 2013 21:11:48 +0200 Subject: [PATCH] reduce memory leak in GtkTreeStore Looks like there's a memory leak when using Gtk.TreeStore.append() with a list of initial values. I've seen this at least on Ubuntu 12.04. Might be bugs.gnome.org/693402 . Even with this workaround, resident memory usage doesn't go down when closing a result panel; but at least that memory is reused when starting a new search. Also there appear to be other memory leaks in pygobject under Ubuntu 12.04, which are fixed eg. in Fedora 19. Test: - start Gedit, and watch its RES memory usage in "top" - start a huge search (eg. search for "a" in /usr/share) - stop search when ca. 300.000 results have been added - note RES memory usage of gedit process - close result pane - start same search again, and cancel it at ca. 300.000 results again - compare current RES memory usage with previous value - good: memory usage has increased by max. 5MB - bad: memory usage has increased by more than 20MB --- file-search/ui.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/file-search/ui.py b/file-search/ui.py index 472ec19..6e258c9 100644 --- a/file-search/ui.py +++ b/file-search/ui.py @@ -586,7 +586,8 @@ def __init__ (self, window, pluginHelper, query): #searchSummary = "searching for %s in %s" % (query.text, query.directory) searchSummary = "" + _("searching for %(keywords)s in %(folder)s") % {'keywords': escapeMarkup(query.text), 'folder': escapeMarkup(GObject.filename_display_name(query.directory))} + "" - self.treeStore.append(None, [searchSummary, '', 0]) + it = self.treeStore.append(None, None) + self.treeStore.set(it, 0, searchSummary, 1, "", 2, 0) self.searchProcess = SearchProcess(query, self) self._updateSummary() @@ -627,7 +628,8 @@ def handleFinished (self): line = "" + ngettext("found %d match", "found %d matches", self.numMatches) % self.numMatches line += ngettext(" (%d line)", " (%d lines)", self.numLines) % self.numLines line += ngettext(" in %d file", " in %d files", len(self.files)) % len(self.files) + "" - self.treeStore.append(None, [line, '', 0]) + it = self.treeStore.append(None, None) + self.treeStore.set(it, 0, line, 1, "", 2, 0) def _updateSummary (self): summary = ngettext("%d match", "%d matches", self.numMatches) % self.numMatches @@ -682,7 +684,8 @@ def _addResultFile (self, filename): directory = os.path.normpath(directory) + "/" line = "%s%s" % (escapeMarkup(directory), escapeMarkup(file)) - it = self.treeStore.append(None, [line, filename, 0]) + it = self.treeStore.append(None, None) + self.treeStore.set(it, 0, line, 1, filename, 2, 0) return it def _addResultLine (self, it, lineno, linetext): @@ -705,7 +708,8 @@ def _addResultLine (self, it, lineno, linetext): if addTruncationMarker: linetext += " [...]" line = "%d: %s" % (lineno, linetext) - self.treeStore.append(it, [line, None, lineno]) + newIt = self.treeStore.append(it, None) + self.treeStore.set(newIt, 0, line, 2, lineno) def on_row_activated (self, widget, path, col): selectedIter = self.treeStore.get_iter(path) @@ -739,6 +743,7 @@ def destroy (self): resultContainer = self.builder.get_object('hbxFileSearchResult') resultContainer.set_data("filesearcher", None) panel.remove_item(resultContainer) + self.treeStore.clear() self.treeStore = None self.treeView = None self._window = None