c++ - shared_ptr to std::vector of shared_ptr data destruction -


this question has answer here:

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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -