News for hackers. Stuff that matters.
Re:So We've Got a Memory Leak by jandrewrogers on Saturday May 11, 2024 @12:55PM (#40329254)
The use of manual memory management increases the cognitive load when reasoning about software. Working memory capacity varies considerably between people and is a performance limiting factor when designing complex systems. You see analogues of this in other engineering disciplines too.

Over my many years of working in software development I have come around to the idea that most software developers do not have sufficient working memory capacity to reason about memory management in addition to everything else they must reason about at the same time. They may know mechanically how to properly do manual memory management but when writing code they drop things if they are juggling too many things at once mentally. It isn't a matter of effort, there simply is a complexity threshold past which something has to give. Automatic memory management has its tradeoffs but it also enables some people to be effective who otherwise would not be.

On the other side of that you have the minority that get manual memory management right every time almost effortlessly, who don't grok why it is so difficult for everyone else because it is literally easy for them. I think some people can't imagine that such a group of engineers exist because they are not in that group and their brain doesn't work that way. If you are in this group, automatic memory management will seem to make things worse for unclear benefit.

I've observed this bifurcation in systems software my entire career. In discussions about memory safety and memory management, it is often erroneously assumed that the latter population simply doesn't exist.

Re:So We've Got a Memory Leak by mattpallissard on Saturday May 11, 2024 @01:55PM (#40329606)
I think the rift comes from people thinking manual memory management is a bunch of random allocs and frees all over the place. That is gross and those of us who don't mind managing memory don't like it either.

Personally my gripe is when people don't think about memory or space complexity at all. I don't care if it's a custom memory management strategy or GC'd language, you need to think about it. I have the same gripe about persistence, socket programming, and database queries.

Abstractions are great, use them, love them. But understanding what the hell they are doing under the hood not only improves efficiency, it prevents bugs, and gives you a really solid base when reasoning about unexpected behavior.

Re:So We've Got a Memory Leak by Dylan16807 on Saturday May 11, 2024 @03:50PM (#40330244)
If the automatic allocation tools are good, then they're doing the same thing as quality manual management but with much more compiler enforcement.
Re:So We've Got a Memory Leak by mattpallissard on Sunday May 12, 2024 @11:08AM (#40335090)
Not exactly, GC is a general solution. Manual management can be tailor made. But to your point more compiler enforcement is a good thing.
Re:So We've Got a Memory Leak by Dylan16807 on Sunday May 12, 2024 @11:17AM (#40335154)
I didn't mean just GC. Automated memory management comes in many forms and can be pretty specific.

And it can be tailored too if a situation really deserves it. If I'm doing something custom I want the smallest amount of code to verify, just the special memory manager and not everything that uses it.

Re:So We've Got a Memory Leak by mattpallissard on Sunday May 12, 2024 @01:32PM (#40336085)
True, I misread your original reply.
Re:So We've Got a Memory Leak by pjmlp on Saturday May 11, 2024 @03:51PM (#40330253)
Which is actually the case in enterprise source code, touched by hundreds of offshoring companies.
Re:So We've Got a Memory Leak by mirsadm on Saturday May 11, 2024 @02:11PM (#40329697)
Any professional developer should understand these things. It was taught at first year of my computer science degree. As you say it isn't particularly difficult if you have a strategy. If you can't manage memory then what about any other resource that needs to be manually closed (sockets, file handles etc ).
Re:So We've Got a Memory Leak by da_chicken on Saturday May 11, 2024 @02:53PM (#40329919)
I'm not sure I understand the causal link between something having a proven track record of being error-prone and not understanding it.
Re:So We've Got a Memory Leak by prerok on Saturday May 11, 2024 @05:00PM (#40330604)
The problem is that automatic memory management means to some newcomers that you don't have to worry about it. Which is not true at all.

These newcomers may have heard about it, may even understand it at some level, but it's not in their rote knowledge. GC is great if you know that every allocation you do is expensive and that you know that it will be taken care of properly, because it will be short-lived.

But I have seen many cases where people just don't have it in their conciousness why allocating huge arrays is a problem or why allocating a new Character object for every single character in a string might be bad. As soon as I point it out, they get it, but it's not like they thought of it while writing their algorithm.

Re:So We've Got a Memory Leak by danielledias204 on Sunday May 12, 2024 @10:34PM (#40339301)
But for most developers using GC (Garbage Collected) languages, not understanding these concepts does not affect their ability to earn a salary and continue working.
Re:So We've Got a Memory Leak by fragmede on Saturday May 11, 2024 @08:14PM (#40331449)
> Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

-Brian Kernighan.

Re:So We've Got a Memory Leak by fransje26 on Sunday May 12, 2024 @06:07AM (#40333304)
I fully agree, and I've learnt that humbling lesson the difficult way. The transition from "I'm elated and proud of the clever solution I wrote" to "I'm too dumb to debug this so I have to rewrite my not-so-clever solution" was sobering. :-) We live and learn.
Re:So We've Got a Memory Leak by hinkley on Sunday May 12, 2024 @02:24PM (#40336399)
Even if you understand every bit of the code, when obscure bugs pop up you have to consider the whole system, and that will quickly overwhelm most people. That’s how pernicious bugs stick around for ages and make the team look like idiots.

Sometimes all you can do is refactor around the problem until you can see it. Or push people to stop being that sort of clever in the first place and write more accessible code.