Reference counting: Difference between revisions

Content deleted Content added
fix sections, remove some redundant text
Dcoetzee (talk | contribs)
Line 20:
 
== Dealing with inefficiency of updates ==
Incrementing and decrementing reference counts every time a reference is created or destroyed can significantly impede performance. Not only do the operations take time, but they damage [[cache]] performance and can lead to [[pipeline bubblesbubble]]s. Even read-only operations like calculating the length of a list require a large number of reads and writes for reference updates with naive reference counting.
 
One simple technique is for the compiler to combine a number of nearby reference updates into one. This is especially effective for references which are created and quickly destroyed. Care must be taken, however, to put the combined update at the right position so that a premature free is avoided.
Line 26:
The Deustch-Bobrow method of reference counting capitalizes on the fact that most reference count updates are in fact generated by references stored in local variables. It ignores these references, only counting references in data structures, but before an object with reference count zero can be deleted, the system must verify with a scan of the stack and registers that no other reference to it still exists.
 
Another technique devised by [[Henry Baker]] involves '''deferred increments''', in which references which are stored in local variables do not immediately increment the corresponding reference count, but instead defer this until it is necessary. If such a reference is destroyed quickly, then there is no need to update the counter. This eliminates a large number of updates associated with short-lived references. However, if such a reference is copied into a data structure, then the deferred increment must be performed at that time. It is also critical to perform the deferred increment before the object's count drops to zero, resulting in a premature free. See the [http://citeseer.nj.nec.com/baker94minimizing.html paper] for more.
 
== Dealing with reference cycles ==