Every New Must Have a Delete
C++ operator new and delete
Although you can use Malloc and free as I explain below, I personally recommend that you use c++ operator new and delete!
This is because C++ operator new properly initializes the vtable (virtual function table) for any virtual functions in your data type, and also calls the constructor for your data type!
FYourDataType* NewDataPtr = new FYourDataType();
Every New Must Have a Delete
Please note you absolutely must pair every use of new with a delete to avoid memory leaks, as you are now doing your own memory management!
delete NewDataPtr;
댓글
댓글 쓰기