[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSGraphicsContext retain cycle
From: |
Alexander Malmberg |
Subject: |
NSGraphicsContext retain cycle |
Date: |
Sat, 23 Feb 2002 15:12:43 +0100 |
Hi again,
In one of the recent NSApplication updates someone added a comment that
GSCurrentContext() wasn't being dealloc:d properly. A quick search in my
retain/release logs showed me that:
1.
[NSGraphicsContext +graphicsContextWithAttributes:] is only
autoreleasing the new context on one of the branches there.
2.
+setCurrentContext: retains the current context, so the current context
can't be dealloc:d by simply releasing it (although it tries to do a
setCurrentContext: nil in -dealloc). I don't know of any nice way to
patch this (the !GNUSTEP_BASE_LIBRARY case is tricky), so I placed a
setCurrentContext: nil (if self is the current context) in
-destroyContext too.
It seems to work, although I don't know what to make of the comment
above -destroyContext (the context will be dealloc:d right away, not in
the next autoreleasepool).
- Alexander Malmberg
Index: Source/NSGraphicsContext.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSGraphicsContext.m,v
retrieving revision 1.50
diff -u -r1.50 NSGraphicsContext.m
--- Source/NSGraphicsContext.m 26 Jan 2002 04:14:38 -0000 1.50
+++ Source/NSGraphicsContext.m 23 Feb 2002 13:39:45 -0000
@@ -153,10 +153,10 @@
@"Internal Error: No default NSGraphicsContext set\n");
ctxt = [[defaultNSGraphicsContextClass allocWithZone: _globalGSZone]
initWithContextInfo: attributes];
- AUTORELEASE(ctxt);
}
else
ctxt = [[self allocWithZone: _globalGSZone] initWithContextInfo:
attributes];
+ AUTORELEASE(ctxt);
return ctxt;
}
@@ -196,6 +196,8 @@
the next autorelease pool end */
- (void) destroyContext
{
+ if (GSCurrentContext()==self)
+ [NSGraphicsContext setCurrentContext: nil];
[contextLock lock];
[contextList removeObject: self];
[contextLock unlock];
- NSGraphicsContext retain cycle,
Alexander Malmberg <=