Category: 

What Is Reference Counting?

Reference counting can be used to streamline memory management on a computer's hard drive.
Article Details
  • Written By: T.S. Adams
  • Edited By: M. C. Hughes
  • Last Modified Date: 16 October 2014
  • Copyright Protected:
    2003-2014
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The oldest known tortoise is 182 years old, and is believed by scientists to be the oldest living land creature.  more...

November 23 ,  1936 :  The modern version of "Life" magazine published its firs  more...

Reference counting is a computer programming technique used to streamline memory management, allowing the computer to instantly know when it is "safe" to release a particular value or block of values from memory. When programming, economy is crucial, so that programs can be run on the widest possible range of computer hardware. Random Access Memory (RAM) is is an important but finite resource for a computer. Keeping program data stored in RAM is one of the fastest ways to improve the response time of a program, but consuming too much system RAM makes the program a resource hog, an undesirable trait from the end-user's point of view. Reference counting acts to balance this by keeping data in RAM just as long as it is needed by the program.

The technique of reference counting works by keeping track of the number and name of the objects the program is using. Think of computer memory like a child's room filled with toys, and storage space on the hard drive like a chest of toys in the room. Reference counting keeps track of the specific "toys" (objects) the program (child) is playing with at any one time; in other words, the number of objects that are currently on the "floor." As soon as the program stops playing with a specific object, reference counting takes note of this, and ships the object back into storage on the hard drive, rather than allowing it to continue eating up space in the RAM.

Ad

When it comes to benefits, the primary advantage of reference counting comes from immediacy. The instant the program finishes with an object, it puts it away, freeing up space for other objects in the program, and for other programs on the computer. From an end-user point of view, this is a very clean approach; the program never takes up more memory than it requires at any specific time.

The downside of this technique is economy. In order for reference counting to operate effectively, it must utilize a perpetual monitoring device to manage the number of objects being used at any one time. This consumes a small portion of memory and CPU capacity, increasing processor overhead from the program. The result is that the decision to use reference counting becomes a balancing act, determining whether the programmer wants to allocate additional stress to the CPU or the RAM.

Ad

More from Wisegeek

You might also Like

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email