r/ProgrammerHumor 23h ago

Meme garbageCollection

Post image
289 Upvotes

32 comments sorted by

106

u/madprgmr 22h 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.

29

u/WernerderChamp 16h ago

The only thing that really matters are GC pauses. This can get problematic if you are going towards 100% CPU.

I never had this as an issue so far.

12

u/DishSoapedDishwasher 15h ago

I have but it was a data pipeline with insane throughput volumes, like tens of terabytes a day per endpoint. It was insane, terribly designed but functional even for a desperate last minute "were dying" solution... But i solved it with literally:

App.init()

gc.collect(2)

Gc.freeze()

App.run()

This way it never runs again as there's no value since it will die in an hour or 6 when the stream ends. Eventually it was rewritten in golang.

13

u/nphhpn 15h ago

Collecting whatever physics engine running in pure Python. Legit why tf are you writing physics engine in Python that stuff should never be in pure Python.

7

u/anto2554 13h ago

For fun

1

u/herbal1st 6h ago

haha yes, engineering a pure pygame 3d voxel engine on cpu came with some interesting challenges..

5

u/Raywell 14h ago

The technique : import C code

1

u/BedSpreadMD 3h ago

But all that requires actual effort.

-27

u/herbal1st 20h ago edited 19h ago

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

19

u/madprgmr 19h 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.

-5

u/aberroco 16h 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.

5

u/madprgmr 16h ago

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

-4

u/aberroco 15h 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 14h 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 14h 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 1h 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).

-10

u/herbal1st 18h 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 😅

35

u/SetazeR 16h ago

Imaginary problems

39

u/NewbornMuse 17h ago

I have programmed a fair amount of python and I have literally never thought "ugh the GC again". Maybe I tried to access a variable that had gone out of scope but that's hardly the GC's fault.

36

u/koanarec 15h ago

This meme literally makes no sense at all

25

u/mmhawk576 16h ago

When do I get to post then next “language bad” shitpost….

9

u/-Kerrigan- 14h ago

Next month it's "Java bad" month cause the new students will first encounter it

4

u/Coulomb111 16h ago

Right now!! This sub is meant for that! Or, if you want to go crazy, you can do 'i just spent 4 hours look for the bug and it was literally just a missing semicolon 🤪'

0

u/herbal1st 6h ago

Please accept my most humble and broken apologies. I am filled with deep shame and remorse for my reckless irresponsibility. I now realize that by utilizing a universally relatable joke framework, I have single-handedly ruined your afternoon and compromised the structural integrity of this subreddit. I will immediately begin a period of self-reflection to contemplate the gravity of my carelessness.
/s 😜

6

u/nonlogin 16h ago edited 2h ago

actually, hoping the garbage collector DOES notice every single piece

3

u/herbal1st 6h ago

agreed, thats usually a great strategy. didnt entirely work for me due to a large amount of objects that need to be created in a 3d voxel engine with physics each frame, and avoiding it is more performant than to just rely on the relatively impactful python gc. so i had to start planning ahead and take the gc into account more than i was used to, which kinda felt like there suddenly were a lot of cheese filled mousetraps to avoid all around 😄

10

u/k-mcm 15h ago

Of all the languages that could have been chosen for a performant physics engine, pure Python wasn't the right answer.

2

u/herbal1st 6h ago edited 6h ago

thats certainly true. it was/is a great project to learn why that is the case though 😅

-8

u/Tyfyter2002 14h ago

Wasn't the right language for anything else either, but some people are terrified of punctuation and want to see as little as possible

3

u/realGharren 7h ago

Certainly one of the takes of all time.

3

u/Fast-Satisfaction482 17h ago

Just null all references that you don't need anymore and you can sneak almost anything past the python GC.

8

u/Ambitious-Sense2769 16h ago

I think you can just use the del keyword as well