Live data from Hacker News

Garbage Collection is Wrong

lb-stuff.com

1–10 of 111 posts

Re: Garbage Collection is Wrong

#5
Meh, GC has its uses. It helps that the vast majority of resources are indeed memory, so it makes sense to special-case.

Although in some situations it isn't acceptable and it's interesting to look at what languages like Rust do about it. It ends up guaranteeing safety, but with not much more effort than GC.

Re: Garbage Collection is Wrong

#7
Yes, in some scenarios you can associate the lifetime of a resource with the lifetime of a storage location, but this simply does not work in all cases, probably only in a small fraction of all cases. And then? How do you handle resources that have no single obvious owner? How do you determine if the resource is still in use when you are done with it in one place? You implement some kind of reference counting? You keep the resource alive until you reach a point where you definitely know it is no longer in use? You turn your code upside down and force it into a single owner structure destroying the semantics of your code on the way?

Re: Garbage Collection is Wrong

#8
In modern C++, using new or delete in your code is wrong. It's not done. Nobody writes code like that anymore in C++.

It's been quite a while since I wrote any significant C++ code, but this statement seems wrong. Is this really "state of the art" for C++?

Re: Garbage Collection is Wrong

#9
post #8

In modern C++, using new or delete in your code is wrong. It's not done. Nobody writes code like that anymore in C++. It's been quite a while since I wrote any significant C++ code, but this statement seems wrong. Is this really "state of the art" for C++?

In practice, no. People still write new and delete all the time in large C++ codebases (LLVM, Gecko, WebKit, etc. etc.)

unique_ptr is gaining traction, of course.

Post reply on HN