NSDocumentDirectory 中的 UIImage 泄漏内存
我目前有这段代码:
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.png", [postsArrayID objectAtIndex:indexPath.row]]]];
它正在加载图像以在 UITableViewCell
中设置。这显然会泄漏大量内存(我确实释放了它,在将单元格图像设置为该图像后向下两行),并且我不确定它是否缓存了图像。
有没有另一种方法,不会泄漏太多,我可以使用多次加载图像,例如在 tableView 中,从我的应用程序的文档目录中加载?谢谢。
I currently have this code:
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.png", [postsArrayID objectAtIndex:indexPath.row]]]];
It's loading in an image to set in a UITableViewCell
. This obviously leaks a lot of memory (I do release it, two lines down after setting the cells image to be that image), and I'm not sure if it caches the image at all.
Is there another way, that doesen't leak so much, I can use to load in images multiple times, like in a tableView, from the Documents-directory of my app? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
leaks
工具或 Instruments 应该告诉您到底泄漏了什么。但是,image
和imageView
属性保留其图像,因此您可能需要确保在dealloc
方法中正确释放它们UITableViewCell。但正如 AngeDeLaMort 所说,我们确实需要更多信息才能给您准确的答案。The
leaks
tool or Instruments should tell you what exactly is leaking. However, theimage
andimageView
properties retain their images, so you may need to ensure you're properly releasing them in thedealloc
method for the UITableViewCell. But like AngeDeLaMort said, we really need more information to give you a precise answer.究竟是什么泄漏?
如果您分配一个图像并在之后释放它,我没有看到您所说的泄漏?也许更多的代码或更精确会有所帮助。
What is leaking exactly?
If you alloc an image and release it after, I don't see the leak your are talking about? Maybe more code or more precision would help.