c++ - shared_ptr to std::vector of shared_ptr data destruction -
this question has answer here:
- how shared pointers work? 5 answers
lets have function returns smart pointer vector of smart pointers data.
shared_ptr<vector<shared_ptr<data>> getvectorptr(); auto vecptr = getvectorptr();
when vecptr goes out of scope , going destroyed shared_ptrs inside deleted?
just knowledge: how smart pointer, internally, realizes went out of scope?
when outer shared pointer goes out of scope (and reference count goes zero), destroys vector. vector in turns destroys elements (the inner shared pointers). when elements reference count goes 0 well, inner objects destroyed, too.
so in case, destruction of inner elements depends on possible other references them.
Comments
Post a Comment