本文介绍了是否有一条快速的规则可以知道何时释放Objective-C变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Objective-C时是否有经验法则可以帮助我了解何时才是释放变量的正确时间?

Are there any rules of thumb when working with Objective-C that would help me understand when is the right time to release variables?

推荐答案

NARC! :)

如果您调用的方法包含 N ew, A lloc, R 容器或 C opy ,那么您必须releaseautorelease.否则,请不要触摸它.

If you invoked a method that contains N ew, A lloc, R etain, or C opy, then you must release or autorelease. Otherwise you don't touch it.

当然,文档中明确指出的任何内容都比这条规则重要.

Of course, anything the documentation explicitly says trumps this rule.

另一件事是,当您处理C函数时,NARC规则仍然适用,但还会获得Create规则:如果该函数包含"create",则您负责CFReleasing或释放返回的数据.

The other thing is that when you're dealing with C function the NARC rule still applies, but also gets the Create rule: if the function contains "create", then you're responsible for CFReleasing or freeing the returned data.

这篇关于是否有一条快速的规则可以知道何时释放Objective-C变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:36