如何找到内存警告的真正原因以及如何在iOS应用中解决 [英] How to find the real cause of memory warning and how to resolve in iOS app

查看:486
本文介绍了如何找到内存警告的真正原因以及如何在iOS应用中解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了许多相关内存管理,ARC,内存管理技术(如 autoreleasepool )的帖子,并使用工具工具来检测哪些代码导致了内存警告但在我的情况下我我无法确定具体原因。



您必须了解的有关该应用的基本信息:


  1. 我们开发了一款iPad应用程序。在某些情况下,我们必须使用超过2000个图像,所以当我的应用程序启动时,我们不想向它们显示占位符图像(客户端要求)。为了实现这一点,我们使用 SDWebImage ,将图像存储在磁盘上,然后我们从那里加载图像。


  2. 我执行了很多核心动画,比如Gennie效果 ,显示弹出窗口和其他许多核心动画。


我们在项目中使用了ARC,我们发现由于内存警告应用程序随机崩溃。



我们使用工具分配来查找脏内存。



以前我们分析日志并在DISK中使用 SDWebImage 存储图像,它解决了经常崩溃的应用程序,但由于内存警告,应用程序仍在崩溃。



当我们深入研究时,我们发现匿名虚拟机在iPad中的任何屏幕切换时都会一直保持内存并且不会释放内存。



以下是我们在设备上分析应用程序的截图。





任何人都应该建议提示或编码技巧或任何我们可以减少内存负载和解决内存警告的想法。



任何帮助将不胜感激。谢谢。

解决方案

在WWDC 2012会话242

Apple建议在拍摄快照之前重复推送pop,我更喜欢推送流行一次。



快照按钮被命名为Mark Generation



您应该多次拍摄快照。



2.



如果你的内存在每个快照之间增长,除了第一个快照之外,您可以深入了解其中一个快照。





按Persitent排序对象,你可能已经看到你的问题ViewController(如果你只推弹出一次)。或者你可以只搜索它。





3.现在你可以深入了解呼叫树,找到并解决问题。



4.您可以使用此技术,不仅可以用于push pop viewControllers,还可以在tableView中滚动,执行databaseSearch和任何其他情况。


I have go through many posts related memory management, ARC , memory management techniques like autoreleasepool and using instruments tool to detect which code is causing memory warning but in my case I am not able to figure out the exact cause.

Basic details which you must know about the app:

  1. We have developed an iPad app. In that we have to use more then 2000 images in some case, so when my app launch we do not want to show them placeholder image (client requirement).so to achieve this, we used SDWebImage , store images on disk and later than we are loading images from there.

  2. There are so many core animation I have performed like "Gennie effect", display pop-up and so many other core animations.

We have used ARC in our project and we found that due to memory warning app is crashing randomly.

We have used Instruments "Allocation" for finding the dirty memory.

Previously we analyze the logs and we stored images with SDWebImage in DISK, it resolve that frequently crashing of app, but still app is crashing due to memory warning.

When we go deep in that we found "Anonymous VM" is keep incrasing and not releasing memory when any screen switch in iPad.

Here is the screenshot of profiling of our app on device.

Anyone please suggest tips or coding techniques or any idea by which We can reduce memory load and resolve memory warning.

Any help will be appreciated. Thanks.

解决方案

In WWDC 2012 Session 242 iOS App Performance: Memory,Apple introduce a way to detect memory problem with Allocations template of Instruments,start from 31 minutes.

1.
Apple suggests push pop repeatedly before take a snapshot of the heap,I prefer push pop just once.

The Snapshot button is Named "Mark Generation"

You should take Snapshot multiple times.

2.

If your memory grow between each Snapshot,You can dig into one of the snapshot except the first one.

Sort the objects by Persitent,you probably has seen your problem ViewController (if you only push pop once).Or you can just search for it.

3.Now you can dig into the call tree ,find and fix the problems.

4.You can use this technique not just for push pop viewControllers,but also scrolling in a tableView ,perform a databaseSearch and any other cases.

这篇关于如何找到内存警告的真正原因以及如何在iOS应用中解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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