mercredi 11 octobre 2017

Memory leak while typecasting normal ptr to unique_ptr

char* newData = new char[100];
node->data = unique_ptr<char []>(newData);

The above code creates a memory leak, so I changed this to the below code.

char* newData = new char[100]; // This line cannot be changed
unique_ptr<char[]>uPtr (newData);
node->data = std::move(uPtr);

Does the below line, create a copy? If so, do I have to delete newData after the above code?

unique_ptr<char[]>uPtr (newData);

Aucun commentaire:

Enregistrer un commentaire