简体   繁体   English

使用Push Segues时iOS摄影画廊内存泄漏/崩溃

[英]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: 如果您想知道如何添加延迟,请查看以下链接:

NSTimer - how to delay in Swift NSTimer-如何在Swift中延迟

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.

相关问题 使用iOS Storyboard Seque“Model”或“Push”样式时是否存在任何内存泄漏(或对象的过度实例化)? - Any memory leak (or over-instantiation of objects) when using iOS Storyboard Seque “Model” or “Push” style? iOS使用图像选择器Memory Leak拍照 - iOS take photo with image picker Memory Leak UISplitViewController在转换为使用iOS 8 Popover Segues时崩溃 - UISplitViewController Crash when converting to use iOS 8 Popover Segues 在iOS中何时使用模态搜索和何时使用推送搜索是否有一般的经验法则? - Is there a general rule of thumb for when to use modal segues and when to use push segues in iOS? iOS推送消息不保留数据 - iOS push segues not keeping data iOS情节提要模态关卡和内存 - iOS Storyboard Modal Segues and Memory iOS NSString stringWithString使用ARC时导致内存泄漏 - iOS NSString stringWithString cause memory leak when using ARC iOS 照片库 - flickr - iOS photo gallery - flickr iOS崩溃,使用NSObject + Rx时的内存管理错误然后呢? - iOS Crash, memory management error when using NSObject+Rx and Then? 从照片库导入图像时出现内存泄漏 - memory leak when importing images from photo library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM