Swift 3/iOS 10 中的漏洞 [英] Leaks in Swift 3 / iOS 10

查看:16
本文介绍了Swift 3/iOS 10 中的漏洞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行仪器并检查泄漏时,它显示的泄漏主要包括:

When I'm running instruments and check for leaks, it's showing leaks mainly consisting of:

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

这是我使用 Swift 3 并在使用 iOS 10 的设备上进行测试的时间.

This is when I'm using Swift 3 and testing on devices using iOS 10.

泄漏只出现在 iOS 10 中,而在 iOS 9.x 上一切似乎都很正常.最重要的是,在 iOS 10 中 UISwitch 似乎也没有解除分配.

The leaks only show up in iOS 10 while on iOS 9.x everything seems to be normal. On top of that, in iOS 10 UISwitch doesn't seem to deallocate either.

目前,我一直在创建各种变通方法,试图避免使用字典和在某些情况下使用数组,这让编码变得非常烦人.

Currently I've been creating all kinds of workarounds trying to avoid using dictionaries and in some cases arrays, making it really annoying to code.

问题:

我是应该关注这个问题并尝试修复所有这些漏洞,还是等待并希望在未来的更新中修复?如果是这样,是否有任何地方可以检查已知的错误等?

Should I be concerned about this and try to fix all these leaks or wait and hope it will be fixed in future updates? If so, is there anywhere to check about which bugs are known etc?

推荐答案

我遇到了同样的问题,花了很多时间去挖掘.我发现如果你从 Objective-C 代码创建一个 Swift 对象并且 Swift 对象有一个原生的 Swift 字典属性,你会看到这个泄漏.如果所有代码都是 Swift,则不会发生这种情况,更有用的是,如果将本机 Swift 字典更改为 NSDictionary,则不会泄漏.这也适用于 Swift Set 和 NSSet.我还看到泄漏发生在 iOS 10 而不是 iOS 9.

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()
}

Leaks Instrument 报告泄漏:
_NativeDictionaryStorageImpl>
_NativeDictionaryStorageOwner>

The Leaks Instrument reports a leak:
_NativeDictionaryStorageImpl<String,String>
_NativeDictionaryStorageOwner<String,String>

这篇关于Swift 3/iOS 10 中的漏洞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆