iOS 7应用程序由于内存压力而终止 [英] iOS 7 App Terminated due to Memory Pressure

查看:118
本文介绍了iOS 7应用程序由于内存压力而终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用大型UIScrollowView的ipad应用程序的两个视图,这似乎导致了内存问题.当内存达到约250MB时,我会收到第一个内存警告.使用Apple Instruments时,以下是全堆"中最大的一个:

I have a two views of an ipad App which utilizes large UIScrollowView's, which appears to be leading to memory issues. I get my first memory warning when memory hits about 250MB. When using Apple Instruments, here are the largest of the All Heap:

VM:ImageIO_JPEG_Data,大小为32.13MB VM:CoreAnimation,大小为32.13MB VM:ImageIO_JPEG_Data,大小为26.64MB ...

VM: ImageIO_JPEG_Data, size 32.13MB VM: CoreAnimation, size 32.13MB VM: ImageIO_JPEG_Data, size 26.64MB ...

滚动视图中有很多图像-所有图像都已加载到情节提要中,我想知道是否减小图像的大小或分辨率可以解决此问题?

I have many images within the scrollview - which are all loaded into the storyboard, and I'm wondering if I reduce the size or resolution of the images it will fix the issue?

推荐答案

您可以设置一个系统,以在滚动视图中的某些点删除/加载某些图像,因此该应用程序仅在用户打算将其存储在内存中时才会将它们存储在内存中.看到他们.

You could set up a system to delete/load certain images at certain points in the scrollview, so the app only has them in memory when the user is about to see them.

因为您说它很大,所以在scrollview的scroll方法中,设置变量以知道scrollview所处的位置(例如:向下一半,滚动10%等).如果用户坐在滚动视图的末尾(即:无法再向下滚动(100%)),则他们不是在完全查看视图顶部的图像.然后,您可以将这些图像设为零,以便应用程序可以重新使用该内存.当用户滚动并且scrollview接近某个百分比时,您可以加载那些用户将要看到的图像,并将其远离的图像置零(这可能会导致几秒钟的空白",当用户正在疯狂地滚动浏览您的应用程序,但这没关系,因为加载图像的时间不会超过几秒钟.

Because you said it's rather large, in the scrollview's scroll method, set variables to know what position the scrollview is in (eg: half way down, 10% scrolled, etc). If the user is sitting at the end of the scrollview (ie: unable to scroll down anymore (100%)) then they're not exactly looking at the images at the top of the view. You could then nil these images so that the app can re-use that memory. When the user is scrolling and the scrollview is near a certain percentage, you can then load those images that the user is about to see and nil the images that the user is far away from (this might cause a few seconds of 'whitespace' when the user is scrolling madly through your app, but that's okay because it won't take more than a few seconds for the images to all load).

因为这些图像已加载到情节提要中,所以我假设您正在通过UIImageView加载它们.只需给每个插座一个插座(按住Control键并单击并将其拖到您班级的.h文件中,然后创建一个IBOutlet),然后当您获得用户向下滚动视图的百分比时,您就可以知道以50%的比例显示,这样我就可以摆脱滚动视图的0-20%和80-100%的图像了, 您可以通过以下方式做到这一点:

Because these images are loaded into storyboard, I'm assuming you're loading them via UIImageView's. Simply give each one an outlet (hold control + click and drag it to your class's .h file and create an IBOutlet), then when you have the percentage of how far the user is down your scrollview you can know 'okay, the user is at 50% so I can get rid of the images from 0-20% and 80-100% of the scrollview', you do this by:

//^Get scrollview scrolled percentage
//^find out where the user is, get a list of UIImageViews that are not visible on the screen  
_yourUIImageView.image = nil //get rid of the image, clear memory up
//then when you need to add it again, assign an image to the UIImageview

希望我能帮上忙.

这篇关于iOS 7应用程序由于内存压力而终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆