Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method used in 3rd-party garbage collector

I am writing to clarify some comments on this website.

1) I know that C++ has no garbage collector. One said that C++ was invented before the idea of garbage collector, so that's the reason. Is that true? I think it makes sense.

2) Whenever garbage collector was discussed, smart point(such as boost::share_ptr) was brought out to be a way. I was once convinced that reference counting is one way to implement garbage collector, but some said, smart point is not an implementation of garbage collector. What's the case?

3) Some said why garbage collector was not included in C++ is because it was hard and a lot of problem couldn't be solved. However, somebody else said that there were 3rd-party garbage collector were available, no matter it is commercial or for-free. So how does these 3rd-party deal with the problems?

I am grateful if anybody could clarify my confusions.

Thanks so much!

like image 733
skydoor Avatar asked Feb 28 '23 12:02

skydoor


1 Answers

  1. no, garbage collection is far older than C++ (many Lisp versions had it in the '60s, in particular).

  2. reference counting is a way to implement garbage collection, but it's quite poor performance-wise (the new Unladen Swallow project, to accelerate the CPython interpreter, includes moving from reference counting to a better garbage collection implementation -- a substantial performance boost).

  3. the Boehm collector for C and C++ uses a conservative approach: briefly, anything that looks like an address is taken to be one (so whatever it might "point to" is not collected). Read the page at the URL I've given, and its outgoing links, for much more information on the subject.

like image 59
Alex Martelli Avatar answered Mar 12 '23 19:03

Alex Martelli