0

Possible Duplicate:
Garbage Collection in C++ — why?

At Going Native 2012 today during Interactive Panel: The Importance of Being Native there was some talk about the future potential of C++ getting a garbage collector. Herb Sutter alluded of it's potential benefits, specifically for a linked list implementations, but wasn't specific. My impression was that RAII is a better/more optimal idiom than automatic garbage collection. What benefits could garbage collection have in modern C++?

Community
  • 1
  • 1
David
  • 27,652
  • 18
  • 89
  • 138
  • Just watch the video feed and he specifically stated what he thought was an ideal canidate for GC. I was there too :) – Michael Dorgan Feb 03 '12 at 03:38
  • 1
    Herb Sutter was probably referring to lock-free linked lists, which require garbage collection, or at least code that amounts to it. – Cubbi Feb 03 '12 at 05:04
  • "My impression was that RAII is a better/more optimal idiom than automatic garbage collection". I have no idea what gave you that impression. RAII can be used to mostly automate scope-based reference counting but that has been regarded as suboptimal for 50 years which is why all modern production garbage collectors use tracing collection and not reference counting. – J D Jun 24 '13 at 23:08

1 Answers1

0

One advantage of garbage collection is that it lets you batch the object deallocations, and have them happen when convenient from a performance standpoint.

It also is more-or-less immune to programmer mistakes causing memory leaks - you have to be clever to escape a garbage collector, and if you were clever you could manage memory explicitly.

Borealid
  • 95,191
  • 9
  • 106
  • 122