2012-07-24 73 views
0

我從來沒有遇到過這樣的問題..現在我不知道如何處理這個問題,並希望得到一些幫助。內存問題iphone

我推視圖控制器(讓我們說exampleViewController)導航控制器。在viewDidload的我的示例viewController中,我添加了一個imageview和一個圖像。在dealloc上,我從superview中刪除這個imageview,然後釋放任何保留的視圖。儀器泄漏工具不顯示任何泄漏,但是當我打開儀器 - 「活動監視器」,然後我看到,當我推我的exampleViewController真正的內存增加了5 MB,當我彈出我的exampleViewController,內存只減少3 MB ..所以如果我推動和彈出這個exampleViewController很多次,我得到一個內存警告,並在該應用程序退出。

我肯定是做錯了什麼,因爲其他視圖控制器的行爲如預期。所以問題是我不知道我做錯了什麼,並希望你們能夠提出一些我如何才能找出造成這種情況的方法。

我試圖像頁頭的工具儀器的一些工具,然後標記堆,還有一些類似的事情,但是,這並不表明什麼被泄露:/

在此先感謝!

編輯:

現在標誌着文書堆的時候似乎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; 

}

+0

如何以模態方式呈現視圖? – Bazinga 2012-07-24 14:10:42

+0

所以你正在手動管理內存而不使用ARC,對嗎? – Lefteris 2012-07-24 14:10:58

+0

是的,我手動管理內存.. @ Kobe.o4我需要推這個視圖控制器,呈現它modally不符合我的需要:/ – Lukas 2012-07-24 14:34:07

回答

0

可能是,如果你的圖像加載了imageNamed,緩存不會被dealloc清空。你是否嘗試過使用

myImageView.image = [UIImage imageNamed:@"someImage.png"]

當然,這可能只幫助「如果」您使用imageNamed與 UIImage *image = [UIImage imageWithContentsOfFile:path];

,而不是加載圖像。

0

...在dealloc的我刪除從上海華這個ImageView的...

-(void)dealloc永遠不要這樣做,因爲此方法應該進行內存管理。

取而代之的是在-(void)viewWillDissappear的imageview(如果你真的需要這個)。至於你的問題,read this,我相信你的問題是在你正在談論的imageView之外的某個地方。

+0

是的,它不是,但爲什麼我不能在dealloc中刪除它? 據我瞭解,如果我添加一個視圖作爲子視圖,它會被保留,所以在我的dealloc中,我從超級視圖中刪除它,並且這減少了它的保留計數,然後它是0,所以視圖得到釋放.. – Lukas 2012-07-24 14:37:15

+0

這將工作如果每次彈出視圖控制器時都會調用dealloc。但這種情況並非如此。如果你收到一個memorywarning afaik,Dealloc只會被調用。所以,如果你想確定,你的viewcontrollers視圖正確釋放,你應該在viewDidDisappear中做到這一點。 – Maverick1st 2012-07-24 14:56:24

+0

@ Maverick1st,你讓我發笑,dealloc在所有類的實例都被釋放後被調用。 - (void)viewDidUnload在內存警告中被調用。 – 2012-07-24 14:58:10