Ask your own question, for FREE!
Computer Science 23 Online
OpenStudy (anonymous):

Will C++ have a garbage collector someday?

OpenStudy (asnaseer):

Maybe - here is a book that discusses this subject: http://accu.informika.ru/accu/bookreviews/public/reviews/g/g000560.htm

OpenStudy (asnaseer):

there is also an interesting article at ACCU on this which discusses the issue for various languages: http://accu.org/index.php/journals/244

OpenStudy (asnaseer):

the latest ACCU edition also has a related article on this called "RAII is not Garbage": http://accu.org/var/uploads/journals/overload106.pdf

OpenStudy (anonymous):

But garbage collector is not very good thing because if program is doing something important maybe in medicine and during surgery runs out of memory and then everything freezes and everyone needs to wait for garbage collector to make more space. That's why important programs is written in c++ not in java

OpenStudy (anonymous):

Wouldn't the same problem occur even in a C++ application?

OpenStudy (anonymous):

you can control memory yourself in c++ but you cant in java

OpenStudy (anonymous):

so you can't delete objects yourself in java?

OpenStudy (anonymous):

yeah

OpenStudy (anonymous):

so it's entirely up to the garbage collector.... write a better garbage collector then!

OpenStudy (anonymous):

one that frees stuff as soon as possible.

OpenStudy (anonymous):

garbage collector is called only when there's no memory left and then he looks which objects are not used and remove it and try to rearrange memory

OpenStudy (anonymous):

i think it wouldn't be efficient to rearrange data every time

OpenStudy (asnaseer):

modern garbage collectors have improved a lot - so you don't get the old-style "freezing" of your application anymore with these types of "incremental" garbage collectors. but @Tomas.A is right is stating that C++ gives you much more control over when and how you want to free up your memory.

OpenStudy (anonymous):

oh well.... garbage collectors are often written in C and C++ anyway :-P

OpenStudy (asnaseer):

see here for How Garbage Collection Works in Java: http://javarevisited.blogspot.com/2011/04/garbage-collection-in-java.html

OpenStudy (asnaseer):

there is also a recent article on InfoQ here: http://www.infoq.com/presentations/Understanding-Java-Garbage-Collection

OpenStudy (anonymous):

yeah my lecturer mentioned that it's possible to have incremental garbage collector but didn't comment anything about it

OpenStudy (shadowfiend):

GC is hard, and there's no efficient way to tell the instant something becomes garbage. That's why you can't just free something as soon as the user is done with it. That said, there are already a couple of garbage collectors out there for C++, including the Boehm garbage collector: http://www.hpl.hp.com/personal/Hans_Boehm/gc/

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!