Mercurial > enso_osx
changeset 24:9f5a0cd8a3f0
Fixed a memory leak, although I suspect that I still don't understand its root cause...
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 01 Mar 2008 11:02:03 -0600 |
parents | 29e9a48350fb |
children | 9109b605bf7c |
files | enso_osx/graphics.py |
diffstat | 1 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/enso_osx/graphics.py Mon Feb 25 20:59:27 2008 -0800 +++ b/enso_osx/graphics.py Sat Mar 01 11:02:03 2008 -0600 @@ -94,8 +94,12 @@ 4 * self.__maxWidth, 32 ) - self._nsContext = AppKit.NSGraphicsContext.graphicsContextWithBitmapImageRep_( self._imageRep ) - self._surface = quartz_cairo_bridge.cairo_surface_from_NSGraphicsContext( self._nsContext, self.__maxWidth, self.__maxHeight ) + # This NSGraphicsContext retains the NSBitmapImageRep we + # pass it, but for some reason it doesn't release it on + # destruction... See this class' __del__() method for how + # we deal with this. + nsContext = AppKit.NSGraphicsContext.graphicsContextWithBitmapImageRep_( self._imageRep ) + self._surface = quartz_cairo_bridge.cairo_surface_from_NSGraphicsContext( nsContext, self.__maxWidth, self.__maxHeight ) return self._surface def setOpacity( self, opacity ): @@ -139,6 +143,18 @@ def getMaxHeight( self ): return self.__maxHeight + def __del__( self ): + if self._surface: + self._surface.finish() + self._surface = None + # Because the NSGraphicsContext we made didn't release the + # NSBitmapImageRep when it was freed, we'll manually release + # it here. + self._imageRep.release() + # Ensure that we're the last object holding on to the + # NSBitmapImageRep. + assert self._imageRep.retainCount() == 1 + def getDesktopSize(): size = AppKit.NSScreen.mainScreen().frame().size return ( size.width, size.height )