Dealing With Reference Cycles
There are a variety of ways of handling the problem of detecting and collecting reference cycles. One is that a system may explicitly forbid reference cycles. In some systems like filesystems this is a common solution. Another example is the Cocoa framework, which recommends avoiding reference cycles by using "strong" (counted) references for "parent-to-child" references, and "weak" (non-counted) references for "child-to-parent" references. Cycles are also sometimes ignored in systems with short lives and a small amount of cyclic garbage, particularly when the system was developed using a methodology of avoiding cyclic data structures wherever possible, typically at the expense of efficiency.
Another solution is to periodically use a tracing garbage collector to reclaim cycles. Since cycles typically constitute a relatively small amount of reclaimed space, the collection cycles can be spaced much farther apart than with an ordinary tracing garbage collector.
Bacon describes a cycle-collection algorithm for reference counting systems with some similarities to tracing systems, including the same theoretical time bounds, but that takes advantage of reference count information to run much more quickly and with less cache damage. It's based on the observation that an object cannot appear in a cycle until its reference count is decremented to a nonzero value. All objects which this occurs to are put on a roots list, and then periodically the program searches through the objects reachable from the roots for cycles. It knows it has found a cycle when decrementing all the reference counts on a cycle of references brings them all down to zero. An enhanced version of this algorithm by Paz et al. is able to run concurrently with other operations and improve its efficiency by using the update coalescing method of Levanoni and Petrank. See the paper for more.
Read more about this topic: Reference Counting
Famous quotes containing the words dealing with, dealing, reference and/or cycles:
“When youre dealing with monkeys, youve got to expect some wrenches.”
—Alvah Bessie, Ranald MacDougall, and Lester Cole. Raoul Walsh. Captain Nelson, Objective Burma, giving a subaltern a mission (1945)
“Youve been trying to keep an honest accounting of city monies. Youve been dealing with politicians. Youve been standing up for your own rights, havent you? Naturally you landed in jail.”
—Dalton Trumbo (19051976)
“Ultimately Warhols private moral reference was to the supreme kitsch of the Catholic church.”
—Allen Ginsberg (b. 1926)
“The stars which shone over Babylon and the stable in Bethlehem still shine as brightly over the Empire State Building and your front yard today. They perform their cycles with the same mathematical precision, and they will continue to affect each thing on earth, including man, as long as the earth exists.”
—Linda Goodman (b. 1929)