When I\'m running instruments and check for leaks, it\'s showing leaks mainly consisting of:
_ContiguousArrayStorage
_NativeDictionaryStorageOw
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 a native Swift dictionary property, you will see this leak. It won't happen if all the code is Swift, and more usefully, it won't leak if you change the native Swift dictionary to an NSDictionary. This also applies to Swift Set's and NSSet's. I also saw that the leak happens 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()
}
The Leaks Instrument reports a leak:
_NativeDictionaryStorageImpl<String,String
>
_NativeDictionaryStorageOwner<String,String
>