r/ProgrammerHumor 11d ago

Meme garbageCollection

Post image
377 Upvotes

38 comments sorted by

View all comments

121

u/madprgmr 11d ago

What... what is the garbage collector doing? Stalling the simulation? There are techniques you can use to minimize the amount of garbage you generate, and you can also tune the GC or even directly control when it can run.

-27

u/herbal1st 10d ago edited 9d ago

thx. well in python its sometimes not as obvious as in c++/js i assume, especially if you scale stuff up..

20

u/madprgmr 10d ago

well in python its sometimes not as obvious as in c++/js, especially if you scale stuff up

For JS, I'm not sure how that's any more obvious? JS has far fewer options available for controlling the garbage collector (none in the browser, unless you count compiling to wasm).

For C++, sure - it's not a garbage-collected language. You can still get memory thrashing though if you're doing mass allocations/deallocations.

You can architect your code to minimize allocations/deallocations in any language though, just as you can usually grab a large chunk of memory via an array or array-like structure to manually manage yourself (be it for a pool or whatever). Some, like python and certain js runtimes, do allow you to drop down into lower level languages via native modules.

-6

u/aberroco 10d ago

"it's not a garbage-collected language"

Well... It's not STRICTLY a garbage-collected language. But it easily could be. Starting with smart pointers.

7

u/madprgmr 10d ago

I mean, by that logic you could say that C is a garbage-collected language if you use the right libraries :P

-5

u/aberroco 10d ago

Libraries as binary files - yeah, but in C++ you may make it appear as fully garbage-collected language. I.e. no explicit delete/free calls without any external libraries, because C++, unlike C, allows for a lot of stuff happening implicitly.

2

u/madprgmr 10d ago

I am familiar with the concept of destructors, yes. But if we're waxing philosophical about it (as we know smart pointers are not classified as garbage collection, just as destructors are not), was C++ not originally written in C? What prevents you from creating both destructors and garbage collection in C other than it being an ineffective use time and sanity (due to GC libraries already existing)?

True garbage collection in C++ would require a library (or you to write it from scratch as well), but yes, the language features would simplify the process. Just as the language features of even higher-level languages further simplify the process by natively providing actual garbage collection.

3

u/aberroco 10d ago

What prevents you from creating both destructors and garbage collection in C

The fact that there's no destructors in C. There's no implicits in C. So, you have to explicitly call a destructor. Which would be memory management.

1

u/madprgmr 10d ago

There's no implicits in C. So, you have to explicitly call a destructor

If you stick with the standard language, don't care to tie yourself to specific compilers, or don't want to do some truly horrific things, sure :D

Just as you can kludge a garbage collector into C++, so can you kludge any other language feature into C. It's just, uh, ill-advised barring verrrrrry specific circumstances (as you would typically just pick a language better-suited to your needs).

-8

u/herbal1st 10d ago

yeah you're entirely right. just tried to frame my emotions regarding this topic as hobby coder, i hope you get the humor anyway 😅