Question about a vector of boost shared_ptr
If I have an attribute of a vector of boost shared_ptr in a class, like this: class A; class B { public : ~B() { ...} private: std::vector< boost::shared_ptr<A> > aVector; }; What do I need to do in the destructor of B so that all the memory used by a vector of shared_ptr of A ('aVector') will be freed correctly? Thank you.
If I have an attribute of a vector of boost shared_ptr in a class, like this:
class A;
class B { public : ~B() { ...} private: std::vector< boost::shared_ptr<A> > aVector;
};
What do I need to do in the destructor of B so that all the memory used by a vector of shared_ptr of A ('aVector') will be freed correctly?
You dont need to do anything in there. If a instance of class B is destroyed, the Vector B::aVector will be destroyed automaticly. If the shared_ptr<A>s are the last shared_ptr<>s to this particular Instance of A, A will also be destroyed. Even if the memory will be freed automaticly, you have to allocate it in the begining, like: aVector.push_back(new A()); Kind Regards, Manuel Jung
Thank you.
participants (2)
-
Manuel Jung
-
Meryl Silverburgh