打开 UIPickerController 并关闭它时出现内存泄漏
这听起来可能是一个新手问题,但我是 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
This may sound a newbie question, however I'm new to iOS dev.
I've following code.
- (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];
}
I'm running the app and profiling for memory leaks, so by just clicking on the button and closing it, without doing anything I am getting memory leak. I'm running this on simulator.
Any ideas why this happens ?
UPDATE : Leak info from profiler's console
Leaked Object,# Address Size Responsible Library Responsible Frame
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要使用 UIImagePickerController 做类似的事情?你实际上是在杀死你真正的rootViewController。
只要删除这一行,一切都会正常工作。
Why would you ever do something like that with a UIImagePickerController? You're literally killing your actual rootViewController.
Just remove this line and everything will work fine.
您应该使用
UINavigationController
并将UIImagePickerController
推送到其上,或者以模态方式呈现UIImagePickerController
。通过将UIImagePickerController
设置为根控制器,您将丢失之前的rootViewController
并且无法返回到它。内存泄漏可能是由于根UIViewController
错误地实现了viewDidUnload
和 dealloc 方法造成的。You should use a
UINavigationController
and push theUIImagePickerController
onto it, or present theUIImagePickerController
modally. By setting theUIImagePickerController
as your root controller you are loosing the previousrootViewController
and will not be able to return to it. The memory leak could be due to the fact that that the rootUIViewController
has incorrectly implementedviewDidUnload
and dealloc methods.