I got to avoid memory management for quite some time
I got to avoid memory management for quite some time

Finally I have a valid reason to learn about memory management. It was also hella weird when encountering it.
I got to avoid memory management for quite some time

Finally I have a valid reason to learn about memory management. It was also hella weird when encountering it.
You're viewing a single thread.
RAII.
Can’t leak what never leaves the stack frame.
Isn’t this for C++?
Classes are just pretentious structs.
How do you get destructor behavior in C?
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.
being inserted automatically.
Aka the entire point of RAII
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.