Live data from Hacker News

Garbage Collection is Wrong

lb-stuff.com

11–20 of 111 posts

Re: Garbage Collection is Wrong

#11
I skim read the article, but I think the author is absolutely right, only for those Resource specific instances he pointed out that need to to have an explicit lifetime.

For everything else, there is garbage collection.

Re: Garbage Collection is Wrong

#12
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++?

It depends a lot on the framework, but you can avoid almost 100% of new and delete on code you have control.

Re: Garbage Collection is Wrong

#14
not even sure where to start...

1. plenty of garbage collectors do not pause all threads or wait for memory to be full.

2. you CAN ask for gc anytime you want in java and in C# (you need not wait for it to happen)

3. new and delete are still integral to C++ (check out any large codebase, like llvm)

Re: Garbage Collection is Wrong

#15
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++?

Professional C++ coder here.

Seeing new and delete has very heavy code smell and can be avoided 99% of the time.

Re: Garbage Collection is Wrong

#16
This is totally on point. Ref-counting / RAII is the only sane way to do resource management. It's super lightweight and easy to understand.

The vast majority of resources are short-lived and don't create cycles. Our garbage collections "systems" should be designed for this case.

Cycles are a special case required for few data structures. They are not the norm and we shouldn't ship a huge heaping mess of a garbage collection system and make everything else slower to account for this rarely used special case.

Anyway people programming today shouldn't be thinking in terms of pointers and references. We should be thinking in terms of VALUES. Finite values have no cycles! The Haskell and C++ community have already embraced this, everyone else is still catching up.

Yet another reason why Java is a horrible language holding people back and the JVM is basically a hamster wheel keeping itself busy.

Re: Garbage Collection is Wrong

#17
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++?

I don't develop C++ professionally or anything, but it's my understanding that a lot of people agree that unique_ptr's and shared_ptr's are the way to go these days.

Re: Garbage Collection is Wrong

#18
post #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 ke…

"Yes, in some scenarios you can associate the life time of a resource with the life time of a storage location"

In what cases is this not possible? I model the resource as an object and that object has a memory location.

(Yes, in a non-deterministic GC, you can't do this for expensive resources, but that's a problem of GCs, not an in-principle problem).

EDIT: I am guessing the parent actually meant "associate the life time of a resource with the life time of a single, non-/never-shared storage location". The statement as written is one I have seen proponents of non-deterministic GCs make.

Re: Garbage Collection is Wrong

#19

not even sure where to start... 1. plenty of garbage collectors do not pause all threads or wait for memory to be full. 2. you CAN ask for gc anytime you want in java and in C# (you need not wait for it to happen) 3. new and delete are still integral to C++ (check out any large codebase, like llvm)

To speak to point 2, of course this is possible but the time it takes to do a GC is not determinable.

As for point 3, just because it's in use, doesn't mean it's correct. With the introduction of unique_ptr, most uses of new and delete can and should be factored out.

Re: Garbage Collection is Wrong

#20
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++?

Naked New/delete have been taboo since auto_ptr hit the scene.
Post reply on HN