2012-02-15 61 views
-2

当最终在仪器测试我的应用程序是否泄漏,我碰到过2个奇数泄漏:奇CoreData内存泄漏

泄露的对象:_PFArray,#:1地址:0x2a11c0尺寸:32个字节负责图书馆:CoreData负责任的框架: newFetchedRowsForFetchPlan_MT

而且

泄露的对象:malloc的16个字节,#:1地址:0x24d6b0尺寸:16个字节负责图书馆:CoreData负责框架:newFetchedRowsForFetchPlan_MT

堆栈跟踪˚F或者这两个泄漏点指向:

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]; 
+0

你释放保留在完成后? – whitelionV 2012-02-15 23:51:55

+0

@whitelionV我在我的MainViewController的dealloc方法中释放记录。 – 2012-02-16 00:18:38

+0

我认为你不必“保留”取得的结果。 – Kjuly 2012-02-16 00:53:32

回答

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]; 
+0

我已经添加了整个代码块。另外,记录数组在整个应用程序中都被编辑并保存到核心数据中。它应该只在视图关闭时释放。谢谢 – 2012-02-16 02:46:33

+0

不,我对记录对象感兴趣。它是.h文件中的保留属性吗?这是你分配的第一个地方吗?无论如何尝试在最后添加autorelease并看看。它应该解决这个问题,因为我不知道你的代码的相关部分。或删除保留并尝试self.records = [[self.managed ... – mbh 2012-02-16 03:05:39

+0

记录数组被声明为:'@property(强,非原子)NSArray *记录;' – 2012-02-16 03:27:14