Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jessegrosjean/dac3a0e4323880de00fbef0055eb9f86 to your computer and use it in GitHub Desktop.
Save jessegrosjean/dac3a0e4323880de00fbef0055eb9f86 to your computer and use it in GitHub Desktop.
// Demos odditly in NSTextStorage subclass deinit.
//
// 1. Profile app in Allocations Instrument
// 2. Notice that after starting app 3 instances of MyTextStorage remain ... even though MyTextStorage.deinit is getting called.
// 3. Comment out the `let _ = self` line and the problem goes away.
// 4. I only notice this problem in subclasses of NSTextStorage, generally `let _ = self` seems fine in an deinit
//
class MyTextStorage: NSTextStorage {
override init() {
super.init()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required init?(pasteboardPropertyList propertyList: AnyObject, ofType type: String) {
fatalError("init(pasteboardPropertyList:ofType:) has not been implemented")
}
deinit {
// Comment this line out and problem goes away.
let _ = self
}
}
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
let _ = MyTextStorage()
let _ = MyTextStorage()
let _ = MyTextStorage()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment