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…
Garbage Collection is Wrong
21–30 of 111 posts
Re: Garbage Collection is Wrong
#22not 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.
"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
#23This 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…
Re: Garbage Collection is Wrong
#24Yes, 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…
Re: Garbage Collection is Wrong
#25Yes, 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…
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
#26This 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.
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
#27This 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.
www.cs.virginia.edu/~cs415/reading/bacon-garbage.pdf
Re: Garbage Collection is Wrong
#28Re: Garbage Collection is Wrong
#29This 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.
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
#30This 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…
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:)