目标c中的内存管理 [英] Memory management in objective c
问题描述
我对内存管理有一个非常基本的怀疑.如果假设iam在viewWillAppear方法中为对象分配内存.我应该在viewWillDisappear方法中释放对象还是在de
Iam having a very basic doubt in memory management. If suppose iam allocating memory for an object in viewWillAppear method. Should i release the object in viewWillDisappear method or in the release all the objects in the de
推荐答案
这是一个关于Objective-C内存管理的非常容易学习的教程.
Here's a very easy to learn tutorial on objective-c memory management.
http://cocoadevcentral.com/d/learn_objectivec/
您将学到很多有关保留和释放变量的知识.通常,变量是根据作用域(即在何处使用)定义的.例如,您可能想初始化一个在viewDidLoad中整个类中使用的变量,然后在dealloc中释放它.这完全取决于您需要在哪里存储数据以及存储多长时间.
You'll learn a lot about retaining and releasing variables. In general variables are defined according to scope (i.e where they will be used) For example, you may want to initialize a variable that's used throughout a class in viewDidLoad and release it in dealloc. It all depends on where you need to store data and for how long.
这篇关于目标c中的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!