Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Garbage Collection Considered Harmful

Name: Anonymous 2014-04-02 2:24

Name: Anonymous 2014-04-02 5:50

Good article. GC is shit. But MMM is shit also.

So let the compiler do it, not runtime!

Consider these examples:

in Java

Integer i = new Integer(1);
// do something with i and forget about it


in C

int* i = malloc(4);
*i = 1;
// do something with i
free(i);


in C++

int i = 1;
// do something with i and forget about it


Now, I guess many C-hackers come yelling here how the C is obviously the best and fastest here and easiest to read and understand since no magic happens. But if you think about, it's the C++ that's really brilliant here.

In Java example, garbage collection handles our memory. In C example, we run much faster since there is no GC, but we have to free the memory ourself. Now, bot Java and C use heap memory for storing the variable. In C++ example, there is no GC and we still don't have to free the memory ourself! How is this possible, you ask? It's because the compiler decides when our variable goes out of scope and frees it for us (C++ supports RAII). As an extra, there is no heap memory allocation here, so it is both faster and safer than the C example. I would also claim that the C++ example is easier to read than the C-example, even though there's quite a lot magic happening there.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List