[ prog / sol / mona ]

prog


Garbage collection

1 2021-11-07 10:12

Why don't C and C++ programmers use GC?
Wouldn't it be appropriate to use garbage collector when building programs that aren't system software? Also, some say that one could use a GC to detect leaks, but I don't fully understand how that works. Wouldn't a GC make it C/C++ more safe and productive (when programming user applications)?
https://www.hboehm.info/gc/
http://tinygc.sourceforge.net/
https://github.com/Ravenbrook/mps

2 2021-11-07 10:18

If I wanted safe systems programming, I'll probably do it in Rust.

3 2021-11-07 10:23

>>2
Sure. But the OP was about user apps and not system software.
P.S.
I would choose Ada.

4 2021-11-07 11:50

If you are going to use a GC, why use C or C++ instead of OCaml?

5 2021-11-07 13:52

>>2 and >>4 nailed it. If you are after features like GC you are not going to use C/C++ in the first place.

GC/non-GC is (to a certain extend) a mindset. Of course you can screw up your memory management royally in C but if that really becomes a regular problem maybe you shouldn't be writing (critical applications in) C. At the very least take a step back and evaluate your style. Chances are you need a bit more training. Everyone is going to make a certain amount of errors but most errors in the memory department can be traced to sloppy coding style or the programmers responsible for it not really understanding what they are doing.

6 2021-11-07 15:10

Why do we even need garbage collection? Nowadays, memory is cheap. When you're about to run out of memory, just buy some more or simply restart your computer. Garbage collection is 20th century "Lisp technology".

7 2021-11-07 16:32

>>6
So is processing power and we obviously can't let that go to waste unused. If there is nothing else it can still be used to collect garbage. Pretty much like in real life.

8 2021-11-07 22:56

Most system software isn't real-time anyway. Considering the amount of memory leaks which still occur, and how slow and unresponsive it becomes anyway, garbage collection would only be an improvement, but they'll never use it until a gun is pointed at their heads.

>>5
Only idiots keep blaming the problems C language programmers repeatedly make on mistakes which could be easily avoided. No one should ever use the C language for anything.

9 2021-11-08 02:12

>>6
Computer bloat tax is a real thing. It occurs over the years as layers upon layers of software-based inefficiencies are stacked upon one another. I don't know if you were around during the Windows 98 era of computing, but it was excruciating to live with Windows systems that were afflicted with bloat tax.

10 2021-11-08 07:32

>>8
Whoa whoa... that's some strong words there. I thought a bit if i correct your nonsense but nah, not worth it. Word of advice though: Blanket statements are usually wrong by definition and making them isn't the wisest idea.

11 2021-11-08 16:47

Things other than the OS shouldn't live long enough to need garbage collection. Just alloc and then when you're program dies the OS recycles all its pages.

12 2021-11-10 13:57

>>4
Daily reminder that the spirit of the C++ language is about metafeatures: the C++ metafeatures exist so that you can write your own "perfect" extension to C++. This implies that people should write their own "perfect" garbage collecting feature in C++.

13 2021-11-11 00:41

We all know C++ has no soul.

14 2021-11-11 04:13 *

>>12-san said spirit not soul but it has neither

15 2021-11-12 06:58

>>10

Blanket statements are usually wrong by definition and making them isn't the wisest idea.

How ironic.

16 2021-11-12 13:20

>>15
Is it? Care to explain how?

17 2021-11-12 18:38

>>16
I waited so long I'd forgotten what I was originally going to retort with. It's ironic because it's a blanket statement about blanket statements.

18 2021-11-12 22:45

>>17
I see. You got a point there. It's the exception that reinforces the rule though.

19 2021-11-13 03:55

>>18
There is the logical fallacy fallacy, even adhominem has legitimate use but that's no fun on the chaosnet.

20 2021-11-15 19:11

>>10
I like the MacOS memory leaks. I can imagine an operating system using garbage collection along with safe manual memory management, think of Ada; most subsystems could have no issues, and the few which do would be handled by the garbage collector, and then fixing those issues becomes a matter of improving efficiency, not correcting flaws which bring down the entire machine.

If they had used a decent language, and so not the C language, they could've easily added this. Now, some could retort that Apple, a mere large multi-national corporation, can't possibly be expected to have decent programmers, and so the memory leaks are their fault, but that's just more reason to have an automatic system which prevents the errors.

Some don't understand computers exist to automate work, however, and instead think they exist so they may appear cool to other people, and they smirk with their incomprehensible and arcane software; such people are despicable after a point.

21 2022-05-04 11:59

It's time for us to read The Garbage Collection Handbook: The Art of Automatic Memory Management in order to become informed citizens.

22 2022-05-04 12:07

They do, they just call it reference counting.

23


VIP:

do not edit these