斯威夫特德code数组定义类内存泄漏 [英] Swift Decode Array Custom Class Memory Leak
问题描述
我节省使用NSCoding我的应用程序的配置和使用德codeWithKey当仪器时,出现了泄漏。
I'm saving my app config using NSCoding and am getting a leak in Instruments when using DecodeWithKey.
设置有一个属性stsSettings
Settings has a property stsSettings
stsSettings = (aDecoder.decodeObjectForKey("stsSettings") as! StsSettings)
stsSettings有StsVariables的属性数组
stsSettings has a property array of StsVariables
stsVariables = (aDecoder.decodeObjectForKey("stsVariables") as! [StsVariable])
泄露的对象#地址大小负责任图书馆负责相框
StsVariable 1 0x7fe182d494f0 192字节基金会_de codeObjectBinary
Leaked Object # Address Size Responsible Library Responsible Frame StsVariable 1 0x7fe182d494f0 192 Bytes Foundation _decodeObjectBinary
设置也有一个属性的转化是转换对象的数组,这不漏,所以我不知道是什么回事。
Settings also has a property conversions which is an array of Conversion objects and this doesn't leak, so I can't work out what's going on.
推荐答案
我经历过类似的情况出现内存泄漏。我被分配去codeD数组一个局部变量解决该问题和元素复制到该属性。但是,我不知道为什么内存泄漏在那里摆在首位。
I experienced a memory leak in a similar situation. I resolved the issue by assigning the decoded array to a local variable and copy the elements to the property. However, I don't know why the memory leak was there in the first place.
let variables = (aDecoder.decodeObjectForKey("stsVariables") as! [StsVariable])
stsVariables = [StsVariable]()
for variable in variables {
stsVariables += [variable]
}
这篇关于斯威夫特德code数组定义类内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!