No, as long my_objectB is not a static member of the class.
If they were created on the heap (using operator new), they will exist until you call "delete" on them.objectB instances inside the vector exist ?
You need to call "delete" on the object to "free" it, pop_back will just remove the pointer from vector, it will not release the associated memory.I have to free every objectB instance inside the vector with pop_back ? Or need I to do more ?
I think you should do some redesign. For example, I have a feeling that at some point you want to delete each object from the vector. This is confusing, because if they all are a members of some ClassA, then it's more "natural" to think that the ClassA instance "owns" instance of ClassB, so it should be responsible for deleting them. If you explicitly delete instance from vector, then you will have a "dangling" pointer in ClassA objects.Any tip ?
Maybe you should use some kind of factory method for creating objects of ClassB instead of storing pointers to members. Or store pointers to ClassA in your vector and make this class responsible for ClassB objects.
Btw if the code snippet (the for loop) is unchanged in your actual code, then probably you have a memory leak - you do not "delete" the ClassA objects.
Bookmarks