简体   繁体   English

保留计数和引用计数之间的区别在哪里?

[英]Where is the difference between Retain Counting and Reference Counting?

我觉得两者是同一回事,但我不确定。

Reference counting is a technique for resource management. 引用计数是一种用于资源管理的技术。 In objective-c the retain method is used to increment the reference count so the terms reference count and retain count are interchangeable. 在objective-c中, retain方法用于增加参考计数,因此参考计数和保留计数这两个术语可以互换。

The Memory Management Programming Guide for Cocoa provides a good overview. 《用于Cocoa内存管理编程指南》提供了很好的概述。

Nothing, they are synonymous: 没什么,它们是同义词:

... An object has a reference count (often called a retain count) and when this reaches zero the object is sent a dealloc message, which cause it to free itself. ...一个对象有一个引用计数(通常称为保留计数),当该引用计数达到零时,将向该对象发送一个dealloc消息,从而使它释放自身。 At the simplest level, every time you want to keep a pointer to an object, you need to send it a retain message: ... 在最简单的级别上,每次您想要保留指向对象的指针时,都需要向其发送一条保留消息:...

... When an app suddenly disappears from the simulator it usually means that the retain count (another name for reference count) has gone to zero, the system cleared it away but you tried to access it! ...当应用突然从模拟器中消失时,通常意味着保留计数(引用计数的另一个名称)已为零,系统将其清除,但您尝试访问它! When you attempt to send a message to a random bit of memory that used to be your object then - puff - you whole app just disappears.... 当您尝试将消息发送到曾经是对象的随机内存时,-吹气-您整个应用程序都消失了...。

(I'm assuming you are just talking about the name and concept retain count, not the method retain) (我假设您只是在谈论名称和概念保留计数,而不是方法保留)

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

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