Iphone 核心数据代码内存泄漏问题
我似乎无法找出泄漏工具报告的问题的原因。这里是有问题的代码,并标记了问题行。有什么想法吗?有没有办法找出泄漏的确切对象Iphone 核心数据代码内存泄漏问题,iphone,objective-c,memory-leaks,Iphone,Objective C,Memory Leaks,我似乎无法找出泄漏工具报告的问题的原因。这里是有问题的代码,并标记了问题行。有什么想法吗?有没有办法找出泄漏的确切对象 NSArray *getAllCoreData(NSString *entityName, NSString *orderedBy, BOOL ascending, BOOL shallow) { // Get the managed object context NSManagedObjectContext *moc = [[AppController sharedAppCo
NSArray *getAllCoreData(NSString *entityName, NSString *orderedBy, BOOL ascending, BOOL shallow)
{
// Get the managed object context
NSManagedObjectContext *moc = [[AppController sharedAppController] managedObjectContext];
// Create a fetch request that fetches from 'entityName'
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:moc];
[fetch setEntity:entity];
// Try to do the fetch
NSError *error;
NSArray *result = [moc executeFetchRequest:fetch error:&error]; <----- Problem line
[fetch release];
// Did the fetch fail?
if (!result)
{
// Display an alert view
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Fetch Failed"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView autorelease];
[alertView show];
return nil;
}
// Return the array of instances of NSManagedObject
return result;
}
NSArray*getAllCoreData(NSString*entityName,NSString*orderedBy,BOOL升序,BOOL浅层)
{
//获取托管对象上下文
NSManagedObjectContext*moc=[[AppController sharedAppController]managedObjectContext];
//创建从“entityName”提取的提取请求
NSFetchRequest*fetch=[[NSFetchRequest alloc]init];
NSEntityDescription*实体=[NSEntityDescription entityForName:entityName inManagedObjectContext:moc];
[获取集合实体:实体];
//试着去取
n错误*错误;
NSArray*result=[moc executeFetchRequest:fetch error:&error];Leaks告诉您,在您没有更多引用之后,分配给那里的内存仍然存在
因此,在您返回结果后,其他一些内容会保留它太长时间,并且在您完成后不会发布。尝试更改
NSError *error;
到
这可能不是真正的泄漏。可能,NSError*error
只是碰巧有一些剩余的指针在里面,所以它看起来像是工具的泄漏。你完全正确!很明显,隧道视觉已经开始,我看不到过去了。我的理智谢谢你。这不是问题,但我也解决了。谢谢。你好,jason、 我也面临着一个类似的问题,所以你能为这个问题张贴解决方案吗?
NSError *error = nil;