free,dealloc,release和autorelease有什么区别? [英] What are the differences between free, dealloc, release, and autorelease?

查看:316
本文介绍了free,dealloc,release和autorelease有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释 free()发布 autorelease dealloc

推荐答案

free()是一个C函数,用于处理通过 malloc()或其他函数获得的不再需要的内存记录要求free()释放其内存例如 strdup()

free() is a C function that you use to dispose of no longer needed memory you obtained through malloc() or other function that is documented to require free() to deallocate its memory e.g. strdup().

-dealloc -C选择器,当对象不再由应用程序的任何部分拥有时,由Objective-C运行时发送到对象。

-dealloc is an Objective-C selector that is sent by the Objective-C runtime to an object when the object is no longer owned by any part of the application.

-release 是发送到对象的选择器,表示您正在放弃该对象的所有权。一旦对象不由任何人拥有,它会被运行时发送 -dealloc 消息。

-release is the selector you send to an object to indicate that you are relinquishing ownership of that object. Once an object is not owned by anybody, it is sent the -dealloc message by the runtime.

-autorelease 是发送到对象的选择器,用于指示您正在放弃对象的所有权。但是如果没有人现在拥有该对象,最后的 -dealloc 将被推迟到一些未指定的稍后点。事实上,你真正做的是将你的所有权转移到一个自动释放池,然后当它自己释放(或消耗)时释放它。

-autorelease is a selector you send to an object to indicate you are relinquishing ownership of the object. However if nobody now owns the object the final -dealloc will be deferred until some unspecified later point. In fact, what you are really doing is transferring your ownership to an autorelease pool which will then release it when it is itself released (or drained).

您不能向 super 以外的对象发送 -dealloc $ c>在对象自己的 -dealloc 方法。

You must never send -dealloc to an object except to super in the object's own -dealloc method.

这篇关于free,dealloc,release和autorelease有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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