[swift-users] Memory Leak Indicated when Derived from NSObject
Ray Fix
rayfix at gmail.com
Fri Dec 16 19:33:28 CST 2016
FWIW, seeing this too. Also, when I boiled the project down to a macOS command line and run the “leaks" cli I don’t see the leak. 🤔
Ray
> On Oct 14, 2016, at 9:42 AM, Chris Chirogene via swift-users <swift-users at swift.org> wrote:
>
> Xcode8 is showing a memory leak in instruments and the memory graph. I have narrowed it down to this: deriving from NSObject produces a leak indication. I have no idea why.
> I need an NSObject to later use the @objc directive.
> The Test instance stored in the mDict Dictionary is indicated as a leak in Xcode.
> This is running as an iOS Single-View-Application project in the iPhone5s Simulator running iOS10.0
> Here is the sample code:
>
> import Foundation
>
> class Test: NSObject // <-- derived from NSObject produces leak indication below
> {
> static var cTest: Test! = nil
> var mDict: [String : Test] = Dictionary<String, Test>()
>
> static func test() -> Void {
> cTest = Test()
> cTest.mDict["test"] = Test() // <-- alleged leak
> }
> }
>
> class Test // <-- NOT derived from NSObject, NO leak indication
> {
> static var cTest: Test! = nil
> var mDict: [String : Test] = Dictionary<String, Test>()
>
> static func test() -> Void {
> cTest = Test()
> cTest.mDict["test"] = Test() // <-- NO leak
> }
> }
>
> // from AppDelegate didFinishLaunchingWithOptions
> // ...
> Test.test()
> // ...
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
More information about the swift-users
mailing list