Leaks in Swift 3 / iOS 10

When I run the tools and check for leaks, it shows leaks, mainly consisting of:

_ContiguousArrayStorage<String> _NativeDictionaryStorageOwner<Int, CGFloat> _NativeDictionaryStorageOwner<String, AnyObject> 

This is when I use Swift 3 and test on devices using iOS 10.

Leaks appear only in iOS 10, but on iOS 9.x everything seems normal. Also, in iOS 10, UISwitch does not seem to be released.

I am currently creating all kinds of workarounds, trying to avoid using dictionaries and in some cases arrays, which makes it really annoying for the code.

Question:

Should I worry about this and try to fix all these leaks or wait and hope that it will be fixed in future updates? If so, where can I check what errors are known, etc.

+6
memory-leaks ios10 swift swift3 instruments
source share
1 answer

I had the same problem and spent a lot of time digging. I found that if you create a Swift object from Objective-C code, and the Swift object has its own Swift dictionary property, you will see this leak. This will not happen if all the Swift code is more useful, it will not leak if you change the Swift native dictionary to NSDictionary. This also applies to Swift Set and NSSet. I also saw that the leak occurs on iOS 10, and not on iOS 9.

 // LeakySwiftObject.swift class LeakySwiftObject: NSObject { let dict = [String: String]() // <- Any native Swift dictionary will reproduce the leak } // ObjectiveCObject.h @class LeakySwiftObject; @interface ObjectiveCObject : NSObject @property (strong) LeakySwiftObject *leaky; @end // ObjectiveCObject.m @implementation ObjectiveCObject - (instancetype)init { self = [super init]; if (self) { self.leaky = [LeakySwiftObject new]; } return self; } @end // ViewController.swift class ViewController: UIViewController { let testObj = ObjectiveCObject() } 

Leaks tool reports a leak:
_NativeDictionaryStorageImpl <String,String >
_NativeDictionaryStorageOwner <String,String >

+4
source share

All Articles