From c6ab27c08caa7039e08b73fdaf803f244aef8d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz?= Date: Fri, 26 Jan 2018 17:45:04 +0100 Subject: [PATCH] Fixes memory leaks on {re,un}do state mutation & resize-related operations. MiRCARTCanvas.py:__del__(): delete canvasMap w/ clear(). MiRCARTCanvasBackend.py:resize(): delete old canvasBitmap w/ Destroy(). MiRCARTCanvasJournal.py:reset{Cursor,Undo}(): delete patches{Cursor,Undo} w/ clear(). MiRCARTCanvasJournal.py:__del__(): provided explicitly to call reset{Cursor,Undo}(). MiRCARTFrame.py:__del__(): provided explicitly to delete panelCanvas. --- MiRCARTCanvas.py | 8 +++++++- MiRCARTCanvasBackend.py | 5 +++-- MiRCARTCanvasJournal.py | 9 +++++++++ MiRCARTFrame.py | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/MiRCARTCanvas.py b/MiRCARTCanvas.py index c62e853..b75af72 100644 --- a/MiRCARTCanvas.py +++ b/MiRCARTCanvas.py @@ -181,8 +181,14 @@ class MiRCARTCanvas(wx.Panel): self.parentFrame.onCanvasUpdate(size=newCanvasSize, undoLevel=-1) # }}} + # {{{ __del__(self): destructor method + def __del__(self): + if self.canvasMap != None: + self.canvasMap.clear(); self.canvasMap = None; + # }}} + # - # _init__(self, parent, parentFrame, defaultCanvasPos, defaultCanvasSize, defaultCellSize): initialisation method + # __init__(self, parent, parentFrame, defaultCanvasPos, defaultCanvasSize, defaultCellSize): initialisation method def __init__(self, parent, parentFrame, defaultCanvasPos, defaultCanvasSize, defaultCellSize): super().__init__(parent, pos=defaultCanvasPos, \ size=[w*h for w,h in zip(defaultCanvasSize, defaultCellSize)]) diff --git a/MiRCARTCanvasBackend.py b/MiRCARTCanvasBackend.py index 154b0ca..f7b20e2 100644 --- a/MiRCARTCanvasBackend.py +++ b/MiRCARTCanvasBackend.py @@ -141,7 +141,8 @@ class MiRCARTCanvasBackend(): newBitmap = wx.Bitmap(winSize) newDc.SelectObject(newBitmap) newDc.Blit(0, 0, *self.canvasBitmap.GetSize(), oldDc, 0, 0) - self.canvasBitmap = newBitmap + oldDc.SelectObject(wx.NullBitmap) + self.canvasBitmap.Destroy(); self.canvasBitmap = newBitmap; self.canvasSize = canvasSize; self.cellSize = cellSize; self._font = wx.Font( \ 8, \ @@ -166,7 +167,7 @@ class MiRCARTCanvasBackend(): # }}} # - # _init__(self, canvasSize, cellSize): initialisation method + # __init__(self, canvasSize, cellSize): initialisation method def __init__(self, canvasSize, cellSize): self._initBrushesAndPens() self.reset(canvasSize, cellSize) diff --git a/MiRCARTCanvasJournal.py b/MiRCARTCanvasJournal.py index d487a60..6bbaa81 100644 --- a/MiRCARTCanvasJournal.py +++ b/MiRCARTCanvasJournal.py @@ -68,10 +68,14 @@ class MiRCARTCanvasJournal(): # }}} # {{{ resetCursor(self): XXX def resetCursor(self): + if self.patchesCursor != None: + self.patchesCursor.clear() self.patchesCursor = [] # }}} # {{{ resetUndo(self): XXX def resetUndo(self): + if self.patchesUndo != None: + self.patchesUndo.clear() self.patchesUndo = [None]; self.patchesUndoLevel = 0; # }}} # {{{ updateCurrentDeltas(self, undoPatches, redoPatches): XXX @@ -80,6 +84,11 @@ class MiRCARTCanvasJournal(): self.patchesUndo[0][1].append(redoPatches) # }}} + # {{{ __del__(self): destructor method + def __del__(self): + self.resetCursor(); self.resetUndo(); + # }}} + # # __init__(self): initialisation method def __init__(self): diff --git a/MiRCARTFrame.py b/MiRCARTFrame.py index 3a3d3bf..4c929dc 100644 --- a/MiRCARTFrame.py +++ b/MiRCARTFrame.py @@ -227,6 +227,12 @@ class MiRCARTFrame(MiRCARTGeneralFrame): toolBar.EnableTool(self.CID_REDO[0], False) # }}} + # {{{ __del__(self): destructor method + def __del__(self): + if self.panelCanvas != None: + del self.panelCanvas; self.panelCanvas = None; + # }}} + # # __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)): initialisation method def __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):