|
From: <md...@us...> - 2009-11-03 13:54:04
|
Revision: 7918
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7918&view=rev
Author: mdehoon
Date: 2009-11-03 13:53:57 +0000 (Tue, 03 Nov 2009)
Log Message:
-----------
Make sure that the FigureCanvas and the View are deallocated.
Previously, the Py_INCREF ensured that the reference count of FigureCanvas
never reaches zero. The FigureCanvas was therefore never deallocated, and
the View remained in memory.
See bug #2889570 on bugzilla, reported by Nicholas Lederer.
Modified Paths:
--------------
trunk/matplotlib/src/_macosx.m
Modified: trunk/matplotlib/src/_macosx.m
===================================================================
--- trunk/matplotlib/src/_macosx.m 2009-11-02 18:58:46 UTC (rev 7917)
+++ trunk/matplotlib/src/_macosx.m 2009-11-03 13:53:57 UTC (rev 7918)
@@ -340,7 +340,8 @@
- (void)dealloc;
- (void)drawRect:(NSRect)rect;
- (void)windowDidResize:(NSNotification*)notification;
-- (View*)initWithFrame:(NSRect)rect canvas:(PyObject*)fc;
+- (View*)initWithFrame:(NSRect)rect;
+- (void)setCanvas: (PyObject*)newCanvas;
- (BOOL)windowShouldClose:(NSNotification*)notification;
- (BOOL)isFlipped;
- (void)mouseDown:(NSEvent*)event;
@@ -2896,10 +2897,22 @@
if(!PyArg_ParseTuple(args, "ii", &width, &height)) return -1;
NSRect rect = NSMakeRect(0.0, 0.0, width, height);
- self->view = [self->view initWithFrame: rect canvas: (PyObject*)self];
+ self->view = [self->view initWithFrame: rect];
+ [self->view setCanvas: (PyObject*)self];
return 0;
}
+static void
+FigureCanvas_dealloc(FigureCanvas* self)
+{
+ if (self->view)
+ {
+ [self->view setCanvas: NULL];
+ [self->view release];
+ }
+ self->ob_type->tp_free((PyObject*)self);
+}
+
static PyObject*
FigureCanvas_repr(FigureCanvas* self)
{
@@ -3243,7 +3256,7 @@
"_macosx.FigureCanvas", /*tp_name*/
sizeof(FigureCanvas), /*tp_basicsize*/
0, /*tp_itemsize*/
- 0, /*tp_dealloc*/
+ (destructor)FigureCanvas_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
@@ -4483,27 +4496,25 @@
return NO;
}
-- (View*)initWithFrame:(NSRect)rect canvas: (PyObject*)fc
+- (View*)initWithFrame:(NSRect)rect
{
self = [super initWithFrame: rect];
rubberband = NSZeroRect;
- if (canvas)
- {
- Py_DECREF(canvas);
- }
- canvas = fc;
- Py_INCREF(canvas);
return self;
}
- (void)dealloc
{
FigureCanvas* fc = (FigureCanvas*)canvas;
- fc->view = NULL;
- Py_DECREF(canvas);
+ if (fc) fc->view = NULL;
[super dealloc];
}
+- (void)setCanvas: (PyObject*)newCanvas
+{
+ canvas = newCanvas;
+}
+
-(void)drawRect:(NSRect)rect
{
PyObject* result;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|