Quick questions about freeing memory

If I have a vector as a instance variable of a class, do I need to free its memory in the deconstructor? I think no, but I just wanted to make sure. I'm also thinking that if it is a vector of pointers, I would need to free those pointers, correct?

Do I need to free strings? I know in C a string is a char*, so you have to call alloc() to create room for the characters. Therefore, you need to free the memory. In C++, isn't a string just a char* as well, so don't I need to free the memory if I declare a string in an object?
do I need to free its memory in the deconstructor?
Only if it's a pointer to a vector and the object has ownership of the pointer (i.e. if it's its job to free it).

I'm also thinking that if it is a vector of pointers, I would need to free those pointers, correct?
Again, only if the object has ownership of those pointers.

Heap C strings should be freed:
char *heapString=new char[n];
//OR
char *heapString=(char *)malloc(n*sizeof(char));
Stack C strings shouldn't:
char stackString[constant];

std::strings shouldn't (and can't) be freed. Pointers to std::strings should.
Thanks!
Topic archived. No new replies allowed.