Skip to content

Commit

Permalink
Fix memleak in Slider/ScrollBar/ScrollArea.unlink()
Browse files Browse the repository at this point in the history
  • Loading branch information
scotty007 committed Oct 19, 2020
1 parent 24dfa7f commit 4bb1163
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions python/libavg/widget/scrollarea.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ def setEnabled(self, enabled):
self.__enabled = enabled
enabled = property(getEnabled, setEnabled)

def unlink(self, kill=True):
super(ScrollArea, self).unlink(kill)
if kill:
if self._hScrollBar:
self._hScrollBar.unlink(True)
self._hScrollBar = None
if self._vScrollBar:
self._vScrollBar.unlink(True)
self._vScrollBar = None

def __onHThumbMove(self, thumbPos):
self.__scrollPane.contentpos = (thumbPos, self.__scrollPane.contentpos.y)
self.notifySubscribers(self.CONTENT_POS_CHANGED, [self.__scrollPane.contentpos])
Expand Down
14 changes: 13 additions & 1 deletion python/libavg/widget/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ def __init__(self, orientation, cfg, enabled=True, height=0, width=0, range=(0.,
self._thumbPos = thumbPos
self.setThumbPos(thumbPos)

self.subscribe(self.SIZE_CHANGED, lambda newSize: self._positionNodes())
self._sizeChangedID = self.subscribe(
self.SIZE_CHANGED, lambda newSize: self._positionNodes())
if orientation == Orientation.HORIZONTAL:
self.size = (width, trackBmp.getSize().y)
else:
Expand Down Expand Up @@ -230,6 +231,17 @@ def setEnabled(self, enabled):

enabled = property(getEnabled, setEnabled)

def unlink(self, kill=True):
super(SliderBase, self).unlink(kill)
self.unsubscribe(self._sizeChangedID)
self.__recognizer.abort()
if kill:
self.__recognizer = None
self._trackNode.unlink(True)
self._thumbNode.unlink(True)
self._trackNode = None
self._thumbNode = None

def _positionNodes(self, newSliderPos=None):
if newSliderPos is not None:
self._thumbPos = float(newSliderPos)
Expand Down

0 comments on commit 4bb1163

Please sign in to comment.