我有这个内存泄漏,在过去一周左右一直非常固执。我在一个名为“ArchiveManager”的类中使用了一个类方法,它将为我解开一个特定的.dat文件,并返回一个包含它的内容的数组。这里是方法:返回对象时发生内存泄漏
+(NSMutableArray *)unarchiveCustomObject
{
NSMutableArray *array = [NSMutableArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithFile:/* Archive Path */]];
return array;
}
我知道我现在没有它的所有权,我将它归还。
CustomObject *myObject = [[ArchiveManager unarchiveCustomObject] objectAtIndex:0];
然后,后来当我解除封存中使用视图控制器(我甚至不创建它的阵列,我也不做它的指针,我只是引用它得到的东西通过unarchiveCustomIbject(objectAtIndex)返回的数组这是仪器被调用内存泄漏,但我不明白这是如何泄露任何想法提前
感谢
编辑:!?。CustomObject的initWithCoder补充:
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init])
{
self.string1 = [aDecoder decodeObjectForKey:kString1];
self.string2 = [aDecoder decodeObjectForKey:kString2];
self.string3 = [aDecoder decodeObjectForKey:kString3];
UIImage *picture = [[UIImage alloc] initWithData:[aDecoder decodeObjectForKey:kPicture]];
self.picture = picture;
self.array = [aDecoder decodeObjectForKey:kArray];
[picture release];
}
return self;
}
编辑2:我做了一个CustomObject的跟踪,并且我意识到在我的应用程序中,另一个对象(OtherObject)具有它的initWithCoder方法分配一个CustomObject的参数,使其保留CustomObject。它看起来像这样:
-(id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init])
{
self.customObject = [aDecoder decodeObjectForKey:kCustomObjectKey];
}
}
您是在模拟器还是在设备上测试?如果您正在使用模拟器,请尝试使用该设备;模拟器经常给内存分析带来错误的结果。 – deanWombourne 2010-03-12 17:58:40
我正在使用该设备。 – skylerl 2010-03-12 18:17:22
你可以发布CustomObject的initWithCoder:方法实现吗? – 2010-03-12 20:52:57