c++ - Does memory that is allocated in a function get freed when function returns? -


i have function allocates memory using new keyword.

that array gets returned function, need somehow free it. ever freed after function returns, or receiving code free array after done it?

should make array member variable, , free in class destructor?

it depends. need define has got ownership of such object.

you can allocate array in function, return it, , let caller free it, or put pointer in class destroy pointer in destructor.

if ownership such object should shared among many entities should use shared_ptr.

i'd suggest use kind of smart pointer handle raw pointers.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -