c++ - Clear the memory after returning a vector in a function -
i have function processes , stores lot of data in , returns results vector of class. amount of data stored in function tremendous , want clear storage memory of function after finished job. necessary (does function automatically clear memory) or should clear memory function?
update:
vector<customers> process(char* const *filename, vector<int> id) { vector<customers> list_of_customers; (perform actions) return list_of_customers; }
variables defined locally within function automatically released @ end of function scope. destructors objects called, should free memory allocated objects (if objects coded correctly). example of such object std::vector
.
anything you've allocated new
must have corresponding delete
release storage. try avoid doing own allocation , use raii instead, i.e. containers or smart pointers.
Comments
Post a Comment