reference counting system

0 views
Skip to first unread message

Jerry

unread,
Sep 15, 2006, 8:28:10 AM9/15/06
to jerry66x
1. A reference is an alternative name for an object.

int i = 1;
int& r = i; // r and i now refer to the same int object
int x = r; // x is 1
r =2; // i is 2

2. Reference counting systems perform automatic memory management by
keeping a count in each object, usually in a header, of how many
references there are to the object. Objects to which there are no
references cannot be accessed by the mutator; they are therefore dead
and may be reclaimed.

引用计数系统主要是为了实现自动存储管理。其原理是为每个对象设置一个计数器(通常在其头部),用于保存指向该对象的引用的个数。如果没有指向某对象的引用,则它就不能被mutator所访问;而表明它已经死亡,可以被回收了。

参照:
http://www.memorymanagement.org/glossary/r.html#reference.counting

Reply all
Reply to author
Forward
0 new messages