this post was submitted on 31 Aug 2025
324 points (96.6% liked)

Programmer Humor

26135 readers
1629 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Finally I have a valid reason to learn about memory management. It was also hella weird when encountering it.

you are viewing a single comment's thread
view the rest of the comments
[–] resipsaloquitur@lemmy.world 9 points 4 days ago (6 children)

RAII.

Can’t leak what never leaves the stack frame.

[–] CookieOfFortune@lemmy.world 10 points 4 days ago (1 children)
[–] resipsaloquitur@lemmy.world 7 points 4 days ago (1 children)

Classes are just pretentious structs.

[–] CookieOfFortune@lemmy.world 3 points 4 days ago (1 children)

How do you get destructor behavior in C?

[–] henfredemars@infosec.pub 2 points 4 days ago* (last edited 4 days ago) (1 children)

You call the destructor. It’s simply not automatically done for you with the concept of going out of scope.

Back when C++ was simply a text pre-processor for C, you could see these normal function calls. You can still see them in the un-optimized disassembly. There’s nothing magical about a destructor other than it being inserted automatically.

[–] entwine@programming.dev 2 points 3 days ago (1 children)

being inserted automatically.

Aka the entire point of RAII

[–] resipsaloquitur@lemmy.world 1 points 2 days ago

The point of RAII is that a resource is allocated and freed in the same scope.

You can free it with an explicit call to a destructor, an implicit call, or with memory allocated on the stack, just wait for the stack frame to be exited.

load more comments (4 replies)