Skip to content

Commit

Permalink
reduce memory leak in GtkTreeStore
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oliver committed Sep 26, 2013
1 parent 1b4ddaa commit 95287ef
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions file-search/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ def __init__ (self, window, pluginHelper, query):

#searchSummary = "<span size=\"smaller\" foreground=\"#585858\">searching for </span><span size=\"smaller\"><i>%s</i></span><span size=\"smaller\" foreground=\"#585858\"> in </span><span size=\"smaller\"><i>%s</i></span>" % (query.text, query.directory)
searchSummary = "<span size=\"smaller\">" + _("searching for <i>%(keywords)s</i> in <i>%(folder)s</i>") % {'keywords': escapeMarkup(query.text), 'folder': escapeMarkup(GObject.filename_display_name(query.directory))} + "</span>"
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()
Expand Down Expand Up @@ -627,7 +628,8 @@ def handleFinished (self):
line = "<i>" + 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) + "</i>"
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("<b>%d</b> match", "<b>%d</b> matches", self.numMatches) % self.numMatches
Expand Down Expand Up @@ -682,7 +684,8 @@ def _addResultFile (self, filename):
directory = os.path.normpath(directory) + "/"

line = "%s<b>%s</b>" % (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):
Expand All @@ -705,7 +708,8 @@ def _addResultLine (self, it, lineno, linetext):
if addTruncationMarker:
linetext += "</span><span size=\"smaller\"><i> [...]</i>"
line = "<b>%d:</b> <span foreground=\"blue\">%s</span>" % (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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95287ef

Please sign in to comment.