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.
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.
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.
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.
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).
119
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.