gpt4 book ai didi

objective-c - 打开和关闭 UIPickerController 时发生内存泄漏

转载 作者:行者123 更新时间:2023-11-28 23:11:50 24 4
gpt4 key购买 nike

这听起来可能是个新手问题,但我是 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

最佳答案

为什么你会用 UIImagePickerController 做这样的事情?你实际上是在杀死你真正的 rootViewController。

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

只需删除这一行,一切都会正常进行。

关于objective-c - 打开和关闭 UIPickerController 时发生内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8020072/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com