0

I have a trivial class containing only an Int. Depending on whether I add an explicit destructor or not, I don't get the same memory leak size in Valgrind. Why is that ?

class Test {
  public:
    // ~Test() {}
    int x;
};

int main(){
  Test* t = new Test[0];
}

Since I create an array of 0 object, I expect to get 0 bytes of leak in Valgrind. I get this answer with the above code. However, when I uncomment the line with the explicit destructor, valgrind gives me 8 bytes of leak.

jaja360
  • 45
  • 1
  • 5
  • This should help. https://stackoverflow.com/questions/41681952/c-virtual-destructor-vtable – Toris Jan 27 '19 at 05:27
  • See also [What happens if I define a 0-size array in C/C++?](https://stackoverflow.com/questions/9722632/what-happens-if-i-define-a-0-size-array-in-c-c) – David C. Rankin Jan 27 '19 at 05:55

0 Answers0