Objective c 打开并关闭UIPickerController时内存泄漏

Objective c 打开并关闭UIPickerController时内存泄漏,objective-c,ios,uipickerview,Objective C,Ios,Uipickerview,这听起来可能是个新手问题,但我对iOS开发还不熟悉 我有以下代码 - (void) onUploadButtonClick { UIImagePickerController* imgPicker = [[UIImagePickerController alloc] init]; [[[UIApplication sharedApplication] keyWindow] setRootViewController:imgPicker]; imgPicker.delega

这听起来可能是个新手问题,但我对iOS开发还不熟悉

我有以下代码

- (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];
}
我正在运行应用程序并分析内存泄漏,所以只要点击按钮并关闭它,而不做任何事情,我就会得到内存泄漏。我在模拟器上运行这个

你知道为什么会这样吗

更新:来自探查器控制台的泄漏信息 泄漏对象,#地址大小负责库负责帧

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
malloc32.50kb,399840 MusicLibrary MemNewPtrClear
Malloc 32.50KB,0xa083800 33280音乐库MemNewPtrClear
Malloc 32.50 KB,0x7840a00 33280音乐库MemNewPtrClear
Malloc 32.50KB,0x7806A0033280音乐库MemNewPtrClear
泄漏对象,#地址大小负责库负责帧
Malloc 32.50KB,0xa083800 33280音乐库MemNewPtrClear
泄漏对象,#地址大小负责库负责帧
Malloc 32.50 KB,0x7840a00 33280音乐库MemNewPtrClear
泄漏对象,#地址大小负责库负责帧
Malloc 32.50KB,0x7806A0033280音乐库MemNewPtrClear
泄漏对象,#地址大小负责库负责帧
Malloc 128.00 KB,0x128de000 131072音乐库可读图像数据库

为什么要用UIImagePickerController做这样的事情?你真的在杀死你真正的rootViewController

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

只要删除这一行,一切都会正常工作。

您应该使用
UIAvigationController
并将
UIImagePickerController
推到它上面,或者以模式显示
UIImagePickerController
。通过将
UIImagePickerController
设置为根控制器,您将失去上一个
rootViewController
,并且将无法返回到它。内存泄漏可能是由于root
UIViewController
错误地实现了
viewDidUnload
和dealloc方法。

实际上,即使删除该行内存,仍然会泄漏。这行代码是为了避免在控制台中跟踪消息,是否有其他方法删除该消息?2011-11-05 16:25:21.791使用两级旋转动画的明信片打印机[4769:207]。要使用更平滑的单阶段动画,此应用程序必须删除两阶段方法实现。2011-11-05 16:25:21.793当旋转多个视图控制器或视图控制器时,不支持使用两阶段旋转动画的明信片打印机[4769:207],而不是窗口委托人找到此链接。希望这会有帮助。是的,我就是这样做的,并在原来的帖子中发布。还在泄漏到底是什么东西泄漏了?在Leaks instrument中,选择Leaks,然后将泄漏的块交换到调用树,并选中左侧的两个框-反转调用树并隐藏系统库。这将向您显示泄漏发生的确切时间以及哪一行给出泄漏。总计%#泄漏字节符号名称100 2 160.50 KB-[MyiewController onUploadButtonClick]这就是我得到的。。。仍然没有任何线索…:(