Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reference counting
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Variant forms== Although it is possible to augment simple reference counts in a variety of ways, often a better solution can be found by performing reference counting in a fundamentally different way. Here we describe some of the variants on reference counting and their benefits and drawbacks. ===Weighted reference counting=== In weighted reference counting, each reference is assigned a ''weight'', and each object tracks not the number of references referring to it, but the total weight of the references referring to it. The initial reference to a newly created object has a large weight, such as 2<sup>16</sup>. Whenever this reference is copied, half of the weight goes to the new reference, and half of the weight stays with the old reference. Since the total weight does not change, the object's reference count does not need to be updated. Destroying a reference decrements the total weight by the weight of that reference. When the total weight becomes zero, all references have been destroyed. If an attempt is made to copy a reference with a weight of 1, the reference has to "get more weight" by adding to the total weight and then adding this new weight to the reference, and then splitting it. An alternative in this situation is to create an ''indirection'' reference object, the initial reference to which is created with a large weight which can then be split. The property of not needing to access a reference count when a reference is copied is particularly helpful when the object's reference count is expensive to access, for example because it is in another process, on disk, or even across a network. It can also help increase concurrency by avoiding many threads locking a reference count to increase it. Thus, weighted reference counting is most useful in parallel, multiprocess, database, or distributed applications. The primary problem with simple weighted reference counting is that destroying a reference still requires accessing the reference count, and if many references are destroyed, this can cause the same bottlenecks we seek to avoid. Some adaptations of weighted reference counting seek to avoid this by transferring weight from a dying reference to an active reference. Weighted reference counting was independently devised by [[David Bevan (mathematician)|Bevan]]<ref>{{cite conference | first=D. I. | last=Bevan | title=Distributed garbage collection using reference counting | book-title=Volume II: Parallel Languages on PARLE: Parallel Architectures and Languages Europe | year=1987 | place=Eindhoven, The Netherlands | pages=176–187 | publisher=Springer-Verlag | isbn=0-387-17945-3 }}</ref> and Watson & Watson<ref>{{cite conference | first1=Paul | last1=Watson | first2=Ian | last2=Watson | title=An efficient garbage collection scheme for parallel computer architectures | book-title=Volume II: Parallel Languages on PARLE: Parallel Architectures and Languages Europe | year=1987 | place=Eindhoven, The Netherlands | pages=432–443 | publisher=Springer-Verlag | isbn=0-387-17945-3 }}</ref> in 1987. ===Indirect reference counting=== In indirect reference counting, it is necessary to keep track of the reference's source. This means that two references are kept to the object: a direct one which is used for invocations; and an indirect one which forms part of a diffusion tree, such as in the [[Dijkstra–Scholten algorithm]], which allows a garbage collector to identify dead objects. This approach prevents an object from being discarded prematurely.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)