简体   繁体   English

如何减少iOS应用中的内存使用

[英]How to reduce memory usage in iOS app

My view contollers are completely dynamic which means controls are added to the view based on a screen xml doc. 我的视图控制器是完全动态的,这意味着将基于屏幕xml文档将控件添加到视图中。 Now my app consumes around 3MB of memory even for orientation change. 现在,即使更改方向,我的应用程序也会消耗大约3MB的内存。 I have seperate screen xml for portrait and landscape!.There is not much images and only I have a background image of size 200kb.I am releasing all alloc memory and dealloc function for release properties.So there is no way to leakage,but the problem may be dynamic controls which are added to the view. 我有用于纵向和横向的单独屏幕xml!没有太多图像,只有背景图像大小为200kb。我正在释放所有alloc内存和dealloc函数以用于释放属性。因此没有办法泄漏,但是问题可能是添加到视图中的动态控件。 Is there any way to solve this. 有什么办法可以解决这个问题。 There are some dictionaries also for caching but do not consumes much memory when the dynamic screen loaded memory shows a hike of 3MB thats the problem. 还有一些字典也用于缓存,但是当动态屏幕加载的内存显示增加3MB时,不会消耗太多内存,这就是问题所在。

Allocate UI elements when they are visible to user. 在用户可见时分配UI元素。 Dont hide UI elements instead remove those from views and release. 不要隐藏UI元素,而是将它们从视图中删除并释放。 If you use @property(nonatomic, retain), those objects will be active until your view controller deallocated. 如果使用@property(非原子的,保留的),则这些对象将一直处于活动状态,直到释放视图控制器为止。

You should move your project to ARC and let the compiler do the retain-release stuff for you. 您应该将项目移至ARC,并让编译器为您完成保留发布的工作。 Choose Edit>Refactor>Convert to Objective-C ARC. 选择“编辑”>“重构”>“转换为Objective-C ARC”。 Also make sure to declare IBOutlet properties as (weak, nonatomic) after moving to ARC. 还要确保在移到ARC之后将IBOutlet属性声明为(弱,非原子)。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM