[英]iOS Photo Gallery Memory Leak / Crash when using Push Segues
I've created a small photo gallery which is presenting a new view controller with a larger version of the photo and some additional text when it is clicked: 我创建了一个小型照相馆,在展示一个新的视图控制器时,该控制器具有较大的照片版本以及单击后的一些其他文本:
The problem is - after going through a handful of images - the application crashes due to overuse of memory. 问题是-经过少量图像处理后,应用程序由于内存过度使用而崩溃。 I attempted to resolve this by compressing the images in order to leave a smaller memory footprint, but the issue remains and I'm not sure what else I can do to resolve this issue.
我试图通过压缩图像来解决此问题,以保留较小的内存占用空间,但是问题仍然存在,并且不确定如何解决此问题。
Also - there is almost no code to doing this since I'm using storyboard's push segues as well as the built in navigation item to go back between viewControllers. 另外-几乎没有代码可以执行此操作,因为我使用情节提要的推送功能以及内置的导航项在viewControllers之间返回。
PS PS
If you feel source code is necessary to provide insight in this instance - it can be found here: 如果您认为有必要提供源代码以了解这种情况-可以在这里找到:
https://www.dropbox.com/s/q1qq8pq4tzv8wyo/EXAMPLE%20BUILD.zip?dl=0 https://www.dropbox.com/s/q1qq8pq4tzv8wyo/EXAMPLE%20BUILD.zip?dl=0
To resolve this issue you have to use this trick; 要解决此问题,您必须使用此技巧。 Put a "placeHolder" image in your cell's imageview in "StoryBoard".
在“ StoryBoard”的单元格图像视图中放置一个“ placeHolder”图像。 Don't load the images all at once in your "ViewController", load them one by one by running a loop or in your "cellForRowAtIndexPath()" method and add a delay in each iteration (Load first image then add a delay, load second image and add a delay, then for third one and so on up to the last image).
不要一次在“ ViewController”中一次加载所有图像,不要通过运行循环或在“ cellForRowAtIndexPath()”方法中一次加载图像,并在每次迭代中添加延迟(先加载图像,然后添加延迟,然后加载第二张图片并添加延迟,然后添加第三张图片,依此类推直到最后一张图片)。
If you want to know how to add a delay then check this link: 如果您想知道如何添加延迟,请查看以下链接:
To resolve this issue I simply resized the images - I noticed I accidentally used a gigantic (6000 x 4000) image and even though I compressed the images iOS had to crunch pretty hard to resize them into the view... thereby causing the memory leak and subsequent crash. 为了解决这个问题,我只是调整了图像的大小-我注意到我不小心使用了一个巨大的(6000 x 4000)图像,即使我压缩了这些图像,iOS也不得不非常努力地将其调整为视图大小,从而导致了内存泄漏。以及随后的崩溃。
Resizing them to 600x400 did the trick. 将大小调整为600x400可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.