2011-11-05 23 views
0

這聽起來可能是一個新手問題,但我是iOS開發新手。打開UIPickerController並關閉內存時出現內存泄露

我下面的代碼。

- (void) onUploadButtonClick 
{ 
    UIImagePickerController* imgPicker = [[UIImagePickerController alloc] init]; 
    [[[UIApplication sharedApplication] keyWindow] setRootViewController:imgPicker]; 
    imgPicker.delegate = self; 
    imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    imgPicker.allowsEditing = NO; 
    [self presentModalViewController:imgPicker animated:YES]; 
    [imgPicker release]; 
} 

我跑的內存泄漏的應用程序和分析,所以只需點擊按鈕,並關閉它,沒有做任何事情我越來越內存泄漏。我在模擬器上運行這個。

任何想法,爲什麼會發生這種情況?

UPDATE:從泄漏事件探查器的控制檯 泄露對象信息,#地址尺寸負責圖書館負責幀

Malloc 32.50 KB,3 <multiple> 99840 MusicLibrary MemNewPtrClear 
Malloc 32.50 KB, 0xa083800 33280 MusicLibrary MemNewPtrClear 
Malloc 32.50 KB, 0x7840a00 33280 MusicLibrary MemNewPtrClear 
Malloc 32.50 KB, 0x7806a00 33280 MusicLibrary MemNewPtrClear 


Leaked Object,# Address Size Responsible Library Responsible Frame 
Malloc 32.50 KB, 0xa083800 33280 MusicLibrary MemNewPtrClear 


Leaked Object,# Address Size Responsible Library Responsible Frame 
Malloc 32.50 KB, 0x7840a00 33280 MusicLibrary MemNewPtrClear 


Leaked Object,# Address Size Responsible Library Responsible Frame 
Malloc 32.50 KB, 0x7806a00 33280 MusicLibrary MemNewPtrClear 


Leaked Object,# Address Size Responsible Library Responsible Frame 
Malloc 128.00 KB, 0x128de000 131072 MusicLibrary ReadITImageDB 

回答

1

你怎麼可能會做這樣的事情用的UIImagePickerController?你真的在殺死你真正的rootViewController。

[[[UIApplication sharedApplication] keyWindow] setRootViewController:imgPicker]; 

只要刪除這條線,一切都會正常工作。

+0

其實即使通過刪除該行內存仍然泄漏。 該行是爲了避免在控制檯中出現以下消息,以任何其他方式刪除該消息? 2011-11-05 16:25:21.791 PostCardPrinter [4769:207]使用兩階段旋轉動畫。要使用更平滑的單階段動畫,此應用程序必須刪除兩階段方法實現。 2011-11-05 16:25:21.793 PostCardPrinter [4769:207]當旋轉多個視圖控制器或視圖控制器而不是窗口委託時,不支持使用兩階段旋轉動畫 – deimus

+0

找到此鏈接。希望它會有所幫助。 http://stackoverflow.com/questions/2878947/getting-using-two-stage-rotation-animation-warning-with-uiimagepickercontrolle – Eugene

+0

是的,這就是我的做法和張貼在原來的帖子。還在泄漏 – deimus

1

您應該使用UINavigationController並將其推入UIImagePickerController,或者以模態方式呈現UIImagePickerController。通過將UIImagePickerController設置爲根控制器,您將丟失之前的rootViewController,並且將無法返回到它。內存泄漏可能是由於根UIViewController錯誤地實施了viewDidUnload和dealloc方法。