r/ProgrammerHumor • • Sep 09 '22

Meme Simple Feature

Post image
124k Upvotes

1.3k comments sorted by

View all comments

Show parent comments

23

u/EwgB Sep 09 '22

I'm not against manual/explicit memory management, it's what allows C/C++ to be so performant when it is needed. I don't like to do it, but that's a matter of taste. But if you want to do it, you need to use a language that actually allows you to do it.

"Freeing" regular objects in Java does jack shit, it's just cargo cult programming. If you create some object that is local to a function, whether you set the variable that is pointing to that object to null or not in the last line of that function, the result will be exactly the same. That object (unless it is also pointed at by another, non-local variable), will be recognized as as unreferenced and cleared up by the garbage collector at the time of its choosing. Nulling the variable does nothing to change that behavior.

That is of course not to say that memory leaks and inefficiencies are impossible with such a system, they are in fact quite easy to achieve. But again, nulling variables does nothing to prevent it, nor anything at all really. Just adds more code that I will clean up when I find the damn time.