- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我试图理解为什么在 UIImage 和 UIImageView 的非常基本的实现中会出现内存泄漏。
在那种情况下我没有使用 ARC(正确禁用)。
我的代码非常简单:
UIImage *image = [UIImage imageNamed:@"my_image.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[[self view] addSubview:imageView];
[imageView release];
我在 UIViewController 的 viewDidLoad:
方法中实现这段代码。
通过调用 UIImage 的方法 imageNamed:
,我知道我会得到一个我不拥有的对象/一个自动释放对象。该对象也将由刚刚实例化的 UIImageView 对象保留。所以我拥有所有权的唯一对象是 UIImageView。
在使用 Memory Leaks Instruments 运行这个应用程序后,我得到了这个报告:
我听说有运行的缓存系统,但我不应该有内存泄漏,因为一些数据被缓存了。
这是对缓存解释的答案的引用: https://stackoverflow.com/a/2930567/1154501
提前致谢!
编辑:也尝试使用 ARC,我遇到了同样的问题。
最佳答案
[UIImage imageNamed:]
由操作系统管理。取消分配从此方法创建的 UIImage 可能会释放已分配的内存。如果您有大量图像或用户生成的内容,您应该使用 [UIImage imageWithContentsOfFile:]
或 [UIImage imageWithData:]
。
如果您使用 [UIImage imageNamed:] 创建过多图像,您的应用可能会因为内存占用而被 iOS 终止。我制作了一个示例应用程序来向自己证明这一点,请在此处查看更多信息:iOS UIImage storage formats, memory usage and encoding / decoding
关于ios - UIImage imageNamed内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19437285/
我正在用 Go 重构服务器端逻辑,但出现无法解决的错误。 ・client: react/axios ・api: golang/gin ・web-server: nginx ・db: mysql ・co
我已经通过 Xcode 本地化了我的图像,所有图像都在正确的 lproj 文件夹中。 但是,当我使用 imageNamed 时,我没有得到正确的图像,但即使我更改了语言,我仍然得到默认图像。 _myI
嗨, 我正在尝试在 UITableView 单元格中使用附加图像。图像位于应用程序包中。除了这张图像和几张图像之外,其他图像在单元格中显示良好。我找不到没有特别显示这张图片的原因。如果您遇到此类问题,
正如问题所述,当资源目录下有多个具有给定名称的文件时,imageNamed 如何工作? 有没有办法区分两个具有相同名称(但路径不同)的不同文件? 谢谢 最佳答案 任何 Xcode 包中的文件夹都是“组
基本上,我的代码大量使用[UIImage imageNamed],默认情况下会从应用程序捆绑包中获取图片。 现在,我希望从文档(或库等)深处的目录(而不是主捆绑包)中返回图像。而且,由于存在太多的im
我最近在我的应用程序中发现了一个相当大的性能问题,这是由于在 [UIImage imagenamed:] 中找不到图像。 我想知道是否有一种“插入式”解决方案可以以某种方式记录这种“错误”?我开始编写
我正在为 iPhone 5 提供支持。我很清楚 Interface Builder 中有 iOS 6 的自动布局功能。这很好,但是如果是 iPhone 5,有时我想加载我自己的图像。 所以我的 iPh
在我的 ios 项目中,我使用以下方法将图像加载到 ImageView: [UIImage imageNamed:@"sample.png"]; 我在项目中使用的这张图片:右键单击项目,添加文件。并将
我在 crashlytics 中为 UIImage imageNamed: 方法列出了一个奇怪的崩溃。此崩溃仅出现在 iOS8 上,对许多用户来说是一个长期存在的问题。虽然,奇怪的是我在测试时无法重现
出于某种原因,以下代码中的保留/释放行为让我完全困惑。 selectedImage = [UIImage imageNamed:@"icon_72.png"]; [selectedImage rele
我的应用程序出现了一些奇怪的问题,它在使用某些 UIImage 时崩溃了。我从图像 Assets 中获取带有 [UIImage imageNamed:@"imageName"] 的图像。但在某些设备上
当我执行以下操作时,我发现 imageNamed 已从可用选项中弃用(或删除): var statusImage:NSImage? = nil self.statusIma
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: iOS 5.1 with Xcode 4.2 and retina in iPad 3 我正在尝试让我的应用
正如标题所说,假设我用 imageNamed: 实例化一个 UIImage 对象。这会创建并返回一个指向自动缓存 UIImage 对象的指针,对吗? 如果框架决定需要清除其缓存(无论出于何种原因,尽管
2014 年 2 月编辑:请注意,这个问题可以追溯到 iOS 2.0!自那时起,图像要求和处理发生了很大变化。视网膜使图像更大并且加载它们稍微复杂一些。凭借对 iPad 和视网膜图像的内置支持,您当然
我正在尝试创建一个程序,该程序将随机生成一张照片。我正在使用此代码来做到这一点: int imageSwitch = rand() % 2; switch (imageSwitch) {
我尝试将 imageNamed: 转换为 imageWithContentsOfFile: 但每次都失败了。我看不到细胞上的图片。 UIImage *image = [UIImage imageNam
我的图像代码是 -(IBAction)start:(id)sender { animation.animationImages = [NSArray arrayWithObjects:
UIImage imageNamed 在 iphone 6 模拟器的 xcode 6 中返回 nil.. 但在 xcode 5 上完美运行 代码: UIImage *img=[UIImage imag
我有一张视网膜图像,我想以 1/2 的分辨率显示。有没有我可以用来以 46px x 40px 而不是 91px x 80px 显示图像的命令? Xcode 中的代码: annView.image =
我是一名优秀的程序员,十分优秀!