back

by dmitrygr·12y ago·view on hn ↗
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)

2 comments
1. Can you give an example of some of these systems?

2. Designing your code in such a way that requires it to invoke the GC seems counter-productive. If your algorithm is producing a bunch garbage that is statically known, why not just release that memory explicitly? Invoking the GC is way more expensive than necessary here.

3. New/delete will always be used in performance critical code but I think the point is that in general it's not a good practice.

1. http://www.azulsystems.com/presentations/qcon-london-2011

2. fair but irrelevant. the argument was that there is no way to make GC happen. It was wrong. I never objected to the (perhaps more interesting) argument that one should be able to manually delete objects

3. then the parent should have said "in toy codebases, whose function is to look pretty, new and delete have no place" instead of a sweeping generalization that all uses of new and delete are archaic and wrong. That one generalization was an insult to every llvm & WebKit developer out there.

Disclaimer: i have no dog in this race - i prefer to work in C and think anyone who cannot free their own memory should maintain a safe 5 meter distance from any compiler. (this is my opinion only, of course)

> 3. New/delete will always be used in performance critical code but I think the point is that in general it's not a good practice.

There's zero runtime overhead to using std::unique_ptr - the compiler will inline the calls to delete you'd otherwise be writing by hand.

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.

No but it is the trajectory of the future and it's very practical. I'm not saying there aren't oddball cases that will require new and delete, but for the most part, it simply isn't necessary.

As for the citation, if you are immersed in the C++ community in general (going native, c++ now, subreddits, irc, accu meetings, etc), it's the general feeling.