0

I have an NSTextView which I programmatically create within the content view of my window. Under certain circumstances I need to programmatically terminate the edit and destroy the NSTextView. When I do this (by setting first responder to nil, removeFromSuperview and releasing my pointer) the dealloc on the NSTextView is not called - until I move my mouse outside of the window content view. It's as though the window is caching a reference to the NSTextView and only releasing it when it decides that I'm no longer interacting with the window. This wouldn't be a problem except that this then messes up the undo grouping for the associated textContainer.

Bit of an obscure one - but if anyone has any knowledge of this I'd love to hear from you!

Thanks

Scotty
  • 2,019
  • 1
  • 20
  • 31
  • You could use Instruments to find out what is retaining the view. Just overrelease it with zombies enabled, and wait for the crash. That might help you track down the problem. – Tom Dalling Jul 04 '13 at 15:15
  • Cracking idea! - just did it and the last thing to have hold of my NSTextView is NSAutomaticFocusRing - whatever that is. Anyway - gives me somewhere to start looking. Thanks – Scotty Jul 05 '13 at 16:44
  • Try `setFocusRingType:NSFocusRingTypeNone`, and also double check that the text view is actually giving up first responder status (`makeFirstResponder:nil` should return `YES`), because only the first responder should have a focus ring. – Tom Dalling Jul 06 '13 at 03:47

1 Answers1

0

Still don't know why NSTextView deallocation is deferred - but it turns out that was a red herring anyway. The reason my undo stack was getting trashed was because I was destroying my NSTextView inside my textDidChange callback (albeit with a retain/autorelease to defer the actual dealloc.)

If I defer my destroyTextView: code by calling it by performSelector:withObject:afterDelay from my textDidChange then all is well (with the undo stack.)

Makes sense now I've found the reason...doesn't it always?

Scotty
  • 2,019
  • 1
  • 20
  • 31