Why does the use of 'new' cause memory leaks?
问题 I learned C# first, and now I'm starting with C++. As I understand, operator new in C++ is not similar to the one in C#. Can you explain the reason of the memory leak in this sample code? class A { ... }; struct B { ... }; A *object1 = new A(); B object2 = *(new B()); 回答1: What is happening When you write T t; you're creating an object of type T with automatic storage duration . It will get cleaned up automatically when it goes out of scope. When you write new T() you're creating an object of