• @[email protected]
    link
    fedilink
    17 months ago

    Is it mandatory in C++? I don’t do much with C++ regularly, but I was under the impression that destructors made it so that you wouldn’t have to manually release memory each time an object was destroyed. Or do you mean specifically regarding pointers to those objects needing to be released as well?

    • @[email protected]
      link
      fedilink
      2
      edit-2
      7 months ago

      When you ever call new/malloc, its mandatory(dynamic allocation). For general programming, the size is usually decided at compilation.

      Yes destructors will unallocate the memory, but the process of writing the destructor is part of the task of memory management

      It becomes madness if you attempt to call dynamic memory outside of a class and its destructor, and hopefully the dev actually remembers to release said memory when their done.