<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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:<div><br></div><div><div>(defclass TRASH-WINDOW (ns:ns-window)</div><div>  ()</div><div>  (:metaclass ns:+ns-object</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>      :documentation "delegate object receiving window events"))</div><div><br></div><div>(objc:defmethod (#/dealloc :void) ((Self trash-window))</div><div>  (print "DEALLOC TRASH WINDOW!!")</div><div>  (call-next-method))</div><div><br></div><div><div>(defparameter *window* (make-instance trash-window</div><div>                         :style-mask (logior </div><div>                                           #$NSTitledWindowMask</div><div>                                            #$NSClosableWindowMask</div><div>                                             #$NSMiniaturizableWindowMask)</div><div>                         :backing     #$NSBackingStoreBuffered</div><div>                         :defer t))</div><div><br></div><div>(defparameter *image-view* (make-instance ns:ns-image-view))</div><div><br></div><div>(#/setContentView: *window* *image-view*)</div><div><br></div><div>(#/orderFront: *window* nil)</div></div></div><div><br></div><div>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.  </div><div><br></div><div>A few other notes: </div><div><br></div><div>• If I do not call (#/setContentView: *window* *image-view*) the window is deallocated with no problems</div><div><br></div><div>• If we set the content view to be a normal NSView and then close the window it is released/deallocated as expected</div><div><br></div><div>• 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.</div><div><br></div><div>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:</div><div><br></div><div></div><div><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #7140a7">// Test Code snipet</span></span></div><div><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #7140a7"><br></span></span></div><div><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #7140a7">NSRect</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "> windowFrame = </span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #3e217f">NSMakeRect</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">(</span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #3031d5">500</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">, </span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #3031d5">500</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">, </span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #3031d5">200</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">, </span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; "><span style="color: #3031d5">200</span></span><span class="Apple-style-span" style="font-family: Menlo; font-size: 11px; ">);</span></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: #7140a7">NSRect</span> viewFrame = <span style="color: #3e217f">NSMakeRect</span>(<span style="color: #3031d5">0</span>, <span style="color: #3031d5">0</span>, <span style="color: #3031d5">200</span>, <span style="color: #3031d5">200</span>);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span style="color: #7140a7">NSWindow</span>* window  = [[<span style="color: #518187">dealloc_window</span> <span style="color: #3e217f">alloc</span>] <span style="color: #3e217f">initWithContentRect</span>:windowFrame</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 33, 127); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                                                      </span></span>styleMask<span style="color: #000000">:</span>NSTitledWindowMask<span style="color: #000000"> | </span>NSClosableWindowMask<span style="color: #000000"> |</span>NSMiniaturizableWindowMask</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(62, 33, 127); "><span style="color: #000000"><span class="Apple-tab-span" style="white-space:pre">                                                  </span></span>backing<span style="color: #000000">:</span>NSBackingStoreBuffered</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">                                                     </span><span style="color: #3e217f">defer</span>:<span style="color: #b930a1">YES</span>];</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><span class="Apple-tab-span" style="white-space:pre">      </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">       </span><span style="color: #7140a7">NSImageView</span>* imageView = [[<span style="color: #7140a7">NSImageView</span> <span style="color: #3e217f">alloc</span>] <span style="color: #3e217f">initWithFrame</span>:viewFrame];</div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px"><span class="Apple-tab-span" style="white-space:pre">      </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">       </span>[window <span style="color: #3e217f">setContentView</span>:imageView];</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><span class="Apple-tab-span" style="white-space:pre">      </span>[window <span style="color: #3e217f">orderFront</span>:<span style="color: #b930a1">nil</span>];</div></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">// snipet from the class "dealloc_window"</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">- (<span style="color: #b930a1">void</span>) dealloc</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">{</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; color: rgb(206, 47, 36); "><span style="color: #000000">    </span><span style="color: #3e217f">printf</span><span style="color: #000000">(</span>"DEALLOC"<span style="color: #000000">);</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">    [<span style="color: #b930a1">super</span> <span style="color: #3e217f">dealloc</span>];</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">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?</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">Thanks,</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Menlo; ">--Mike</div></div></body></html>