【发布时间】:2012-03-07 09:19:02
【问题描述】:
在 Instruments 中最终测试我的应用程序是否泄漏时,我遇到了 2 个奇怪的泄漏:
泄漏对象:_PFArray,#:1 地址:0x2a11c0 大小:32 字节负责库:CoreData 负责帧:newFetchedRowsForFetchPlan_MT
还有
泄漏对象:Malloc 16 字节,#:1 地址:0x24d6b0 大小:16 字节负责库:CoreData 负责帧:newFetchedRowsForFetchPlan_MT
两个泄漏的堆栈跟踪都指向:
records = [[self.managedObjectContext executeFetchRequest:request error:&error] retain];
在 CoreData Fetch 中。
还有
[self.window makeKeyAndVisible];
这些泄漏是什么?我以前从未见过他们。当我构建和分析时,它们不会弹出。有人有什么建议吗?
谢谢!!
编辑:
这里是围绕记录数组的代码。 Records 只是在 .h 中声明的 NSarray。
/*
Fetch existing events.
Create a fetch request; find the Event entity and assign it to the request; add a sort descriptor; then execute the fetch.
*/
marblebeingdragged=YES;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Child" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
// Order the events by creation date, most recent first.
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSSortDescriptor *prizeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"prize" ascending:NO];
NSSortDescriptor *neededDescriptor = [[NSSortDescriptor alloc] initWithKey:@"marblesneeded" ascending:NO];
NSSortDescriptor *colorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"color" ascending:NO];
NSSortDescriptor *reachedDiscriptor = [[NSSortDescriptor alloc] initWithKey:@"prizereached" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:nameDescriptor,prizeDescriptor,neededDescriptor,colorDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
[nameDescriptor release];
[colorDescriptor release];
[prizeDescriptor release];
[neededDescriptor release];
[reachedDiscriptor release];
[sortDescriptors release];
// Execute the fetch -- create a copy of the result.
NSError *error = nil;
records = [[self.managedObjectContext executeFetchRequest:request error:&error] retain];
【问题讨论】:
-
完成后是否释放保留?
-
@whitelionV 我在 MainViewController 的 dealloc 方法中释放记录。
-
我认为你不必
retain获取的结果。
标签: iphone objective-c ios core-data memory-leaks