我的应用内存有问题。我检查了 Instruments 以获得关于这个问题的更多线索,我发现我 79% 的内存被这个占用了:
所以我在谷歌上搜索了一下,有人说这是图像缓存,它把我所有的图像都保存在内存中。也许它来 self 的分配?
这是我如何称呼我的图像:
info = [InfoModel getInfo:[NSString stringWithFormat:@"%d", self.idEnigme]];
myImage = [UIImage imageNamed:[NSString stringWithFormat:@"res/img/%@", [info objectForKey:@"path1"]]];
myImageView = [[UIImageView alloc] initWithImage:myImage];
myImageView.frame = CGRectMake(0, 200, [[UIScreen mainScreen] bounds].size.width, 400);
[self.scrollView addSubview:myImageView];
Info 是一个类,我在其中解析 Json 文件,其中是我的图像路径。
感谢您的帮助,这让我发疯。
最佳答案
当您调用 imageNamed:
正如在几个地方所讨论的,包括这里:Does UIImageView cache images?
如果您知道您只打算创建一次缓存,则可以绕过此缓存
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]]
代替
关于ios - IOS 上的图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22539104/