Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: All
May 5, 2000

Models of Garbage Collectors

If you need a garbage collector, you can either install one or implement it by yourself. Which type of garbage collection should you use? A conservative garbage collector and a copying garbage collector are the two most common models.

A conservative garbage collector doesn't move objects from one place to another. It uses constant-sized memory chunks (buckets). This way, the heap doesn't become fragmented. The conservative model is more adequate for C++ because sometimes copying objects is undesirable or even impossible, especially if they contain pointers to other objects or data. A conservative garbage collector is also easy to implement. A copying garbage collector gives you more flexibility at the cost of higher runtime overhead. Under the copying model, memory blocks may have different sizes. As a result, heap fragmentation can occur. Therefore, a copying garbage collector must perform memory compaction periodically. During memory compaction, "live" objects are copied from their existing location to a contiguous memory block and their previous storage is recycled. Compaction is very expensive. Therefore, it's less useful in time critical systems.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap