奇数核心数据内存泄漏

时间:2012-02-15 23:47:54

标签: iphone objective-c ios core-data memory-leaks

当最终测试我在仪器中的应用程序泄漏时,我遇到了两个奇怪的泄漏:

泄露对象:_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];

这些泄漏是什么?我以前从没见过他们。当我构建和分析时,它们不会弹出。有人有什么建议吗?

谢谢!

修改

这是记录数组的代码。记录只是在.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];

1 个答案:

答案 0 :(得分:2)

您需要释放“记录”对象。并且你需要在使用它之后释放它,而不是在dealloc方法中。发布更多代码。你是如何定义记录的?如果您需要任何帮助,请发布整个核心数据代码块。

records = [[self.managedObjectContext executeFetchRequest:request error:&error] retain];
//.... code using records
[records release];

编辑:

使用此

records = [[self.managedObjectContext executeFetchRequest:request error:&error]]; // no retian

或者这个

records = [[[self.managedObjectContext executeFetchRequest:request error:&error] retain] autorelease];