new operator lifetime

A class has a method that initializes one of it's member pointers with the new operator. Will it be deallocated when the class is deallocated or only when the entire program is deallocated?
Will it be deallocated when the class is deallocated


No. You must delete things you allocate with new, otherwise they are never deallocated.

Typically you would put the delete in your destructor. (Or use a smart pointer class)
As Disch mentioned, the memory allocated for the data member will not be deallocated when the object is ending its life. Simple rule is that, whenever you use "new" it has to be deallocated by "delete" only and nothing else.(Or after the execution of the program is over)
Topic archived. No new replies allowed.