开发者

NSKeyedUnarchiver causing memory leak

开发者 https://www.devze.com 2022-12-10 14:22 出处:网络
I have a memory leak problem, I\'m saving an array into a file using: [NSKeyedArchiver archiveRootObject:myArray toFile:MyFile];

I have a memory leak problem, I'm saving an array into a file using:

[NSKeyedArchiver archiveRootObject:myArray toFile:MyFile]; 

the objects included into the array have the following methods:

- (id)initWithCoder:(NSCoder *)coder
{

[super init];

parameter1 = [[coder decodeObject] retain];
parameter2 = [[coder decodeObject] retain];
parameter3 = [[coder decodeObject] retain];

return self;
 }

- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:parameter1];
[coder encodeObject:parameter2];
[coder encodeObject:parameter3];
}

To unarchive the objects I'm using:

myUnarchivedArray = [NSKeyedUnarchiver unarchiveObjectWithFile:myFile];

The application suddenly crashes because the available memo开发者_如何学编程ry is not enough to continue.

I'm unable to deallocate myUnarchivedArray and the Intruments tool is telling me that the unarchiver is causing the memory leak.

I haven't search too much, I just found the cause of the memory leak, but I was hopping to find someone that has been passed the same problem and has a tip to solve it.:)

Thank you!! Anna


You're retaining your objects in initWithCoder although the documentation states:

NSKeyedUnarchiver’s implementation, however, returns an autoreleased object, so its life is the same as the current autorelease pool instead of the keyed unarchiver.

0

精彩评论

暂无评论...
验证码 换一张
取 消