问题描述:app 出现内存偏高的问题,app 是一个展示图片居多的app,浏览多个图片list 页以后,内存最高峰值跑到了150m,然后app 出现了闪退;
问题:
① 怎么能够避免内存偏高的问题?
② 如果不能避免那么怎么降低内存偏高呢?
③ 如果上面两个问题都不能解决,那么出现内存偏高的时候怎么处理可以避免闪退呢?
阿神2017-04-18 09:20:33
Please make sure to try the real device release mode for testing
Please make sure the memory is not leaked
ringa_lee2017-04-18 09:20:33
As mentioned above, first check whether there is a memory leak.
1. What is the cause of crash? If you don't see the log, you can't be sure that it is caused by high memory.
2. If you browse the list of images, you can use SDWebImage or the like to cache the images, set the upper limit of the memory used by the cache, and reuse the table, which will not use a lot of memory.
天蓬老师2017-04-18 09:20:33
If too many pictures are displayed and the memory increases, first check whether the pictures have been released. Under normal circumstances, the pictures are not released in time.
PHP中文网2017-04-18 09:20:33
If the memory suddenly becomes high after a certain operation and remains stable or continues to rise, it can basically be determined to be a memory leak.
When judging a memory leak, first, you should determine where the memory leak occurs in the code;
Second, if it is caused by pictures, it may be because the network requested pictures do not have a local cache;
Third, pay attention Network requests, database operations, release of UIView classes and subclasses.
Finally, you can debug the project in XcodeProduct->Profile
, wait for the compilation to be completed, call up Instruments, and use Leaks to check memory leaks.
PHP中文网2017-04-18 09:20:33
A more common image optimization may also be that the images in the original data are too large, causing the memory to increase. It is recommended to use thumbnails in lists.
ringa_lee2017-04-18 09:20:33
I think the pictures on the cells that slide out of the screen are not released. Generally speaking, the cells that slide out of the screen will be released-->The content in the cell is released-->UIImageView is released-->Then UIImage Release, check whether there is a link in the release chain that has not been released. It is more likely that your UIImage object is referenced elsewhere, such as stored in NSArray, such as in NSCache. Release means saving this object without any strong references