Do I need a "new char []" unlock "?

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

Should I call delete[] m_sFilename; someday?

and

use delete[] m_sFilename or delete m_sFilename; ?

+4
source share
4 answers

Does the "new char []" need to be freed "manually?

Yes.

To do this: m_sFilename = new char [len+1]; Should I call delete[] m_sFilename; someday?

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.

+7
source

Yes, if you do not want the memory allocated by the new[] tag to leak, you must delete[] when you are finished using this memory.

To avoid having to keep track of this memory, I recommend using std::string or std::vector instead.

+4
source

Yes, but use std::string to store m_sFilename instead - best of all anyway.

+2
source

For native data types and user data types that do not have destructors using delete or delete[] , will mean the same thing. The primary heap manager will free up all memory. But calling scaler delete on the vector new ( new[] ) will not result in calling all destructors. The destructor will be called only once for the very first object.

The behavior above depends on the compiler / heap manager (which handles new and delete ). For better portability, use scaling delete to scale new and vector delete ( delete[] ) for vector new .

0
source

All Articles