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

          • henfredemars@infosec.pub
            link
            fedilink
            English
            arrow-up
            2
            ·
            edit-2
            19 days ago

            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.

              • resipsaloquitur@lemmy.world
                link
                fedilink
                arrow-up
                2
                ·
                18 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.