Last active
June 19, 2016 16:13
-
-
Save jessegrosjean/dac3a0e4323880de00fbef0055eb9f86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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