从核心数据列表中删除NSEntityDescription对象
问题描述:
我想从核心数据中删除所有的NSEntityDescription对象并释放内存。该reset
功能没有任何差别的内存从核心数据列表中删除NSEntityDescription对象
下面是我的代码
-(void)generatePersons: (NSManagedObjectContext *)privatecontext{
self.persons = [[NSMutableArray alloc]init];
[privatecontext performBlockAndWait:^{
for(int i = 1; i< self.dataRows.count; i++){
NSArray *HeaderRow = [self.dataRows objectAtIndex:1];
NSArray *dataRow = [self.dataRows objectAtIndex:i];
if (dataRow.count <= HeaderRow.count){
int index = 0;
Person *person = (Person *)[NSEntityDescription
insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:privatecontext];
[self.persons addObject:person];
}
}
[privatecontext reset];
}];
}
这个代码[privatecontext reset];
理论上设定的背景下其基本状态,在我的理解它会释放内存,以及但它不会并保持相同的内存数量
答
尝试在您的块中使用对自身的弱引用。
创建块的inline声明前参考:
__weak __block __typeof(&*self)weakself = self;
然后用weakself
代替self
那里。这可能会阻止线程释放其内存。
+0
之后仍然占用相同的内存量,您误解了这个问题。 –
所有这些实例仍然由您的数组保留。 –
@TomHarrington即使我们评论此行''self.persons addObject:person];'即使在退出for循环范围和等待块范围 –