I am a bit confused about the method of issuing a unique pointer. Here is my sample program.
class Test { public: Test(){std::cout << "ctor" << std::endl;} ~Test(){std::cout << "dtor" << std::endl;} }; int main() { std::unique_ptr<Test> ptr(new Test()); ptr.release(); // memory leak //ptr.reset(); // this is ok but not necessary return 0; }
Conclusion:
ctor
Since it does not print dtor, I assume that it does not call the destructor Test, which will lead to a memory leak. Is it ?
dtor
Test
The word releasemeans "free ownership for the caller." So no, the destructor is not called by him.
release
, delete release d , reset, ., , .
delete
reset
Source: https://habr.com/ru/post/1547108/More articles:Cannot add file to solution: "A file or folder with the name [name] already exists” - c #How to control hover effect in CSS3? - javascriptConvert io.BytesIO to io.StringIO to parse an HTML page - htmlWhat is the best way to multiply a large and sparse matrix with its transposition? - c ++How to press 3 keys at a time using KeyPress? - c #Multiple Left Registration on the same table - sql3 divs regroup stack div on mobile devices - cssLimit file upload size in asp.net - c #How to beat NSMutableArray performance with Swift (beta) array? - performancePostgreSQL update - postgresqlAll Articles