Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does "new char[]" need to be release resources manually?

Tags:

c++

For this: m_sFilename = new char [len+1];

Should I call delete[] m_sFilename; sometime?

And:

should I use delete[] m_sFilename or delete m_sFilename;?

like image 831
David Degea Avatar asked Dec 12 '22 10:12

David Degea


1 Answers

Does "new char[]" need to be release resouces manually?

Yes.

For this: m_sFilename = new char [len+1]; Should I call delete[] m_sFilename; sometime?

Yes.

Should I use delete[] m_sFilename or delete m_sFilename;?

delete[].


But you should actually use std::string, which does all this for you, and is free.

like image 122
Lightness Races in Orbit Avatar answered Jan 04 '23 02:01

Lightness Races in Orbit