View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum01 Final Exam Review: Garbace Collection


1) Three reasons why garbabe collection is a convience to the
programmer:

- programmer dosen't have to analyise program and decide when to free
- code is cleaner and smaller, making it easier to read
- don't know



Reasons for using a GC.

programmer doesn't have to worry about memory management.
reduce risk of memory leaks.
it will reclaim memory as needed (if possible)

reference counting:
advantage: relatively easy to implement, just increment and decrement a counter as pointers are added/removed, and easy to understand
disadvantage: for small blocks of memory, storage taken up by counters becomes a large percentage of the memory itself, and a little more time is taken to increment/decrement the counters

mark and sweep:
advantage: must only be run once in a while, when there is no more free memory
disadvantages: time consuming when run, must be the only thing running so will not suffice for any type of real-time system
– axiom

Reference Counting

advantages: no pause time, easy to implement
disadvantages: can't reclaim cycles (leads to memory leaks)

Mark & Sweep

advantages: does not have problem reclaiming cycles
disadvantages: leads to fragmentation during allocation from free list

Stop & Copy

advantages: very fast allocation, no fragmentation during allocation
disadvantages: long pause times

Stephen Mallory

These are great answers. Be aware that some of these advantages and disadvantages apply to more than one GC strategy. (And thus, there are more possible answers to this question, even just by reusing material on this page!) -Lex Spoon


re: Stephen Mallory's answer.

I'm not sure how Stop & Copy would have "long" pause times compared to Mark & Sweep. S&C collection would be proportional to the size of the live data - it just has to copy over the live data to the other semispace. M&S collection is also proportional to the live data when using a free-space pointer.

The penalty of S&C collection is space. Only half the total heap can be used - although fragmentation makes M&S less than optimal in this area as well.






Link to this Page