What is the difference between delete and calling destructor in C++

后端 未结 2 1348
盖世英雄少女心
盖世英雄少女心 2020-12-14 12:21

As stated in the title, here is my code:

class Foo {

    public:
        Foo (int charSize) {
            str = new char[charSize];
        }
        ~Foo (         


        
相关标签:
2条回答
  • 2020-12-14 13:10

    Calling a destructor releases the resources owned by the object, but it does not release the memory allocated to the object itself. The second code snippet has a memory leak.

    0 讨论(0)
  • 2020-12-14 13:19

    Whenever a call to destructor is made , the allocated memory to the object is not released but the object is no longer accessible in the program. But delete completely removes the object from memory.

    0 讨论(0)
提交回复
热议问题