Live data from Hacker News

Garbage Collection is Wrong

lb-stuff.com

21–30 of 111 posts

Re: Garbage Collection is Wrong

#21
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 lif…

For example, two lists both contain a reference to the same object. Neither one is a sole owner, and you can't safely destroy the object until both lists are destroyed.

Re: Garbage Collection is Wrong

#22

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.

Can you give an example of any codebase not using any new or delete at all that compares in size?

"Right or Wrong" are irrelevant in the face of "Practical or Not".

The fact that all large pieces of serious code use new and delete would either imply that the author is smarter than all the people writing that code combined, or (more likely) he did not consider something w.r.t. the practicality of not using them.

Let me go further and explain my original post in a more succinct fashion:

One giant [[citation needed]] on every claim in this article, including, but not limited to, new and delete being useless.

Re: Garbage Collection is Wrong

#23
post #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 co…

RAII is great, and should be used where appropriate. I'm not sure what it has to do with reference counting, though. Reference counting is just a particularly slow and unreliable form of garbage collection; I don't see why you would ever prefer it to a proper garbage collector.

Re: Garbage Collection is Wrong

#24
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 lif…

[deleted]

Re: Garbage Collection is Wrong

#25
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…

Examples of a situation where you don't want a resource associated with a variable/storage location?

Global variables exist and can be used to hold resources. If you have a resource that's not associated with any single function context you can move it into the global variable.

Re: Garbage Collection is Wrong

#26
post #23
post #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 co…

RAII is great, and should be used where appropriate. I'm not sure what it has to do with reference counting, though. Reference counting is just a particularly slow and unreliable form of garbage collection; I don't see why you would ever prefer it to a proper garbage collector.

Classic RAII in C++ is a limited form of ref-counting (only one ref).

I have to disagree with your second statement, ref-counting is extremely fast. If you consider it a GC then it's the fastest GC. It's also deterministic and does not pause.

Re: Garbage Collection is Wrong

#27
post #23
post #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 co…

RAII is great, and should be used where appropriate. I'm not sure what it has to do with reference counting, though. Reference counting is just a particularly slow and unreliable form of garbage collection; I don't see why you would ever prefer it to a proper garbage collector.

Tracing and Refcounting are each others duals,

www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf

Re: Garbage Collection is Wrong

#29
post #23
post #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 co…

RAII is great, and should be used where appropriate. I'm not sure what it has to do with reference counting, though. Reference counting is just a particularly slow and unreliable form of garbage collection; I don't see why you would ever prefer it to a proper garbage collector.

Because it is deterministic? (i'm just guessing that what you call "proper" garbage collector is non-deterministic).

Furthermore, the only "advantage" I see in garbage collectors is that they can deal with cycles.

I say "advantage" because i'm of the strong opinion that having a cycle in your code is a software design error.

Re: Garbage Collection is Wrong

#30
post #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 co…

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

Many modern GC systems are tuned for exactly this. It often is called generational garbage collection and the youngest generation is tuned to quickly collect these short-lived and non cyclic objects.

I used to work in this field so I've got at least a decent grasp of what modern GC's do and don't do well:)

Post reply on HN