[Openmcl-devel] NSWindow deallocation seems to work differently in CCL then it does in an XCode based application
Michael Minerva
minerva at agentsheets.com
Fri Dec 16 12:06:00 PST 2011
I have been trying to figure out why some of our Cocoa objects do not get properly decollated and I created a simple example in CCL that seems to be at the heart of my problem:
(defclass TRASH-WINDOW (ns:ns-window)
()
(:metaclass ns:+ns-object
:documentation "delegate object receiving window events"))
(objc:defmethod (#/dealloc :void) ((Self trash-window))
(print "DEALLOC TRASH WINDOW!!")
(call-next-method))
(defparameter *window* (make-instance trash-window
:style-mask (logior
#$NSTitledWindowMask
#$NSClosableWindowMask
#$NSMiniaturizableWindowMask)
:backing #$NSBackingStoreBuffered
:defer t))
(defparameter *image-view* (make-instance ns:ns-image-view))
(#/setContentView: *window* *image-view*)
(#/orderFront: *window* nil)
If you run this little example it will create a window with an NSImageView inside and show it, so far so good. Now when I close this window I am a little surprised to see that the #/dealloc method of my trash-window never gets called.
A few other notes:
• If I do not call (#/setContentView: *window* *image-view*) the window is deallocated with no problems
• If we set the content view to be a normal NSView and then close the window it is released/deallocated as expected
• This problem is not specific to the NSImageView being the window's content view. If I create an NSView and an NSImageView then set the NSView to be the NSWindow's content view and make the NSImagevVew a subview of the NSView then close this window, dealloc is still not called.
So when I found all this I decided it must be some oddity of Cocoa so I decided to do the same sort of thing in an XCode/Cocoa example before trying to consult the Cocoa gurus, but to my surprise, my XCode example seems to behave differently:
// Test Code snipet
NSRect windowFrame = NSMakeRect(500, 500, 200, 200);
NSRect viewFrame = NSMakeRect(0, 0, 200, 200);
NSWindow* window = [[dealloc_window alloc] initWithContentRect:windowFrame
styleMask:NSTitledWindowMask | NSClosableWindowMask |NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
defer:YES];
NSImageView* imageView = [[NSImageView alloc] initWithFrame:viewFrame];
[window setContentView:imageView];
[window orderFront:nil];
// snipet from the class "dealloc_window"
- (void) dealloc
{
printf("DEALLOC");
[super dealloc];
}
When I ran this example which programmatically creates an NSWindow with an NSImageView as its content view and then close the NSWidnow, strangely dealloc IS called. It seems to be that these two examples are basically the same but seem to exhibit very different behavior. Anyone have any clues about what could be going on here?
Thanks,
--Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20111216/933d4ede/attachment.htm>
More information about the Openmcl-devel
mailing list