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.
This commit is contained in:
Lucio Andrés Illanes Albornoz 2018-01-26 17:45:04 +01:00
parent 579dd858ba
commit c6ab27c08c
4 changed files with 25 additions and 3 deletions

View File

@ -181,8 +181,14 @@ class MiRCARTCanvas(wx.Panel):
self.parentFrame.onCanvasUpdate(size=newCanvasSize, undoLevel=-1) 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): def __init__(self, parent, parentFrame, defaultCanvasPos, defaultCanvasSize, defaultCellSize):
super().__init__(parent, pos=defaultCanvasPos, \ super().__init__(parent, pos=defaultCanvasPos, \
size=[w*h for w,h in zip(defaultCanvasSize, defaultCellSize)]) size=[w*h for w,h in zip(defaultCanvasSize, defaultCellSize)])

View File

@ -141,7 +141,8 @@ class MiRCARTCanvasBackend():
newBitmap = wx.Bitmap(winSize) newBitmap = wx.Bitmap(winSize)
newDc.SelectObject(newBitmap) newDc.SelectObject(newBitmap)
newDc.Blit(0, 0, *self.canvasBitmap.GetSize(), oldDc, 0, 0) 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.canvasSize = canvasSize; self.cellSize = cellSize;
self._font = wx.Font( \ self._font = wx.Font( \
8, \ 8, \
@ -166,7 +167,7 @@ class MiRCARTCanvasBackend():
# }}} # }}}
# #
# _init__(self, canvasSize, cellSize): initialisation method # __init__(self, canvasSize, cellSize): initialisation method
def __init__(self, canvasSize, cellSize): def __init__(self, canvasSize, cellSize):
self._initBrushesAndPens() self._initBrushesAndPens()
self.reset(canvasSize, cellSize) self.reset(canvasSize, cellSize)

View File

@ -68,10 +68,14 @@ class MiRCARTCanvasJournal():
# }}} # }}}
# {{{ resetCursor(self): XXX # {{{ resetCursor(self): XXX
def resetCursor(self): def resetCursor(self):
if self.patchesCursor != None:
self.patchesCursor.clear()
self.patchesCursor = [] self.patchesCursor = []
# }}} # }}}
# {{{ resetUndo(self): XXX # {{{ resetUndo(self): XXX
def resetUndo(self): def resetUndo(self):
if self.patchesUndo != None:
self.patchesUndo.clear()
self.patchesUndo = [None]; self.patchesUndoLevel = 0; self.patchesUndo = [None]; self.patchesUndoLevel = 0;
# }}} # }}}
# {{{ updateCurrentDeltas(self, undoPatches, redoPatches): XXX # {{{ updateCurrentDeltas(self, undoPatches, redoPatches): XXX
@ -80,6 +84,11 @@ class MiRCARTCanvasJournal():
self.patchesUndo[0][1].append(redoPatches) self.patchesUndo[0][1].append(redoPatches)
# }}} # }}}
# {{{ __del__(self): destructor method
def __del__(self):
self.resetCursor(); self.resetUndo();
# }}}
# #
# __init__(self): initialisation method # __init__(self): initialisation method
def __init__(self): def __init__(self):

View File

@ -227,6 +227,12 @@ class MiRCARTFrame(MiRCARTGeneralFrame):
toolBar.EnableTool(self.CID_REDO[0], False) 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 # __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)): def __init__(self, parent, appSize=(840, 630), defaultCanvasPos=(0, 75), defaultCanvasSize=(100, 30), defaultCellSize=(7, 14)):