Skip to content
DevMeme
5848 of 7590
Languages Post #6405 · source on Telegram

In C++, You Are the Garbage Collector

Description

A two-part meme comparing memory management in Java and C++. The top section has text that reads, 'Java: Don't worry about memory leaks, we have a special program for that. Garbage collector does that for you'. Below this, under the label 'C++:', is a portrait photo of a weary-looking, balding man with glasses, a checkered shirt, and a red jacket. The final punchline is at the bottom: 'My brother, you are the garbage collector'. The meme humorously contrasts Java's automated garbage collection with C++'s manual memory management. In C++, the developer bears the full responsibility for allocating and deallocating memory, a task that can be complex and error-prone. The image of the stressed individual represents the burden placed on the C++ programmer, who effectively must act as the 'garbage collector' themselves, a concept deeply familiar to any engineer who has worked with lower-level languages

Comments

18
Anonymous ★ Top Pick In Java, you pray the garbage collector is efficient. In C++, you pray the developer who wrote the memory allocation code wasn't having an off day
  1. Anonymous ★ Top Pick

    In Java, you pray the garbage collector is efficient. In C++, you pray the developer who wrote the memory allocation code wasn't having an off day

  2. Anonymous

    Java’s GC stops the world for 200 ms; C++’s “GC” stops the sprint for a two-week code review while five seniors argue over who actually owns the pointer

  3. Anonymous

    After 20 years of explaining RAII and smart pointers to junior devs, you realize the real garbage collection was the segfaults we debugged along the way

  4. Anonymous

    The eternal struggle: Java developers sleep soundly while the GC pauses their application at 3 AM, while C++ developers lie awake wondering if they remembered to delete that pointer from 2015. At least in C++ you control when your application freezes - it's called a segfault, and it's a feature, not a bug. The real garbage collector was the memory discipline we learned along the way

  5. Anonymous

    In Java you tune GC; in C++ you tune yourself - RAII, smart_ptrs, and Valgrind - because on that runtime, you are the collector

  6. Anonymous

    Java outsources janitorial work to GC; C++ hands you a broom called RAII - and Valgrind conducts your performance review when you forget std::unique_ptr

  7. Anonymous

    Java's GC: outsourcing memory cleanup so you can focus on stop-the-world pauses during Black Friday traffic spikes

  8. @as_suguri 1y

    you are the garbage

    1. @Johnny_bit 1y

      That's what the elites want you to think in order to keep you down! Remember - it's garbage-CAN not garbage-CANNOT.

  9. @Agent1378 1y

    My brother hand me those pointers!

  10. @TheFloofyFloof 1y

    Doesn't c++ actually have a garbage collector?

    1. @Araalith 1y

      It has destructor at least

      1. @Agent1378 1y

        If implemented by programmer, lol

        1. @AlexKart20129 1y

          The default destructor always exist, even if it wasn't implemented explicitly.

          1. @Agent1378 1y

            Yeah, but it only frees memory taken by the object itself, doesn't free any internal objects.

  11. @Araalith 1y

    Circular references say "Hello!"

  12. @AlexKart20129 1y

    There will be no memory leak if you don't use the 'new' operator.

  13. @TheRamenDutchman 1y

    Rust: Can't have a garbage collector if you don't have garbage to begin with!

Use J and K for navigation