【发布时间】:2012-07-22 21:06:03
【问题描述】:
我以前从来没有遇到过这样的问题。现在我不知道如何处理这个问题,希望能得到一些帮助。
我正在将视图控制器(比如说 exampleViewController)推送到导航控制器。在 viewdidload 上的 exampleViewController 中,我添加了一个带有图像的 imageview。在 dealloc 上,我从 superview 中删除了这个 imageview,然后释放任何保留的视图。仪器泄漏工具没有显示任何泄漏,但是当我打开仪器-“活动监视器”然后我看到当我推动我的 exampleViewController 时,实际内存增加了 5 MB,而当我弹出我的 exampleViewController 时,内存只减少了 3 MB .. 所以如果我多次推送和弹出这个 exampleViewController,我会收到内存警告,然后该应用程序退出。
我肯定做错了什么,因为其他视图控制器的行为符合预期。所以问题是我不知道我做错了什么,希望你们提出一些方法来找出导致这种情况的原因。
我在工具中尝试了一些工具,比如 alloc 工具,然后标记堆,以及一些类似的东西,但这并没有显示什么被泄露:/
提前致谢!!
编辑:
现在在仪器中标记堆时,executeFetchRequest: 似乎正在泄漏,我做错了什么吗?
+ (Question *)getQuestionWithId:(NSString *)questionId
{ 问题 *resultQuestion = nil;
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
//geting context from appdelegate
NSManagedObjectContext *context = appDelegate.managedObjectContext;
//form fetch request with predicate
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Question"
inManagedObjectContext:context];
NSPredicate *query = [NSPredicate predicateWithFormat:@"questionId=%@",questionId];
NSPredicate *query1 = [NSPredicate predicateWithFormat:@"type='ke'"];
NSPredicate *predicates = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:query,query1, nil]];
[fetchRequest setPredicate:predicates];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
resultQuestion = [fetchedObjects lastObject];
return resultQuestion;
}
【问题讨论】:
-
以模态方式呈现视图怎么样?
-
所以您是手动管理内存而不是使用 ARC,对吗?
-
是的,我正在手动管理内存。@Kobe.o4 我需要推送这个视图控制器,以模态方式呈现它不符合我的需求:/
-
在我看来,您没有释放您在通知中传递的对象。你在处理通知的方法中做了什么?
-
@Maverick1st 不,我正在发布它:/ 也许您知道一些可以帮助我追踪泄漏的工具或方法?仪器中的泄漏工具不显示泄漏..
标签: iphone objective-c ios memory-management memory-leaks