c++ - Memory leak using shared_ptr -


both code examples compile , run without problems. using second variant results in memory leak. ideas why? in advance help.

variant 1:

typedef boost::shared_ptr<parametertabelle> spparametertabelle;  struct partabspaltedata {       partabspaltedata(const spparametertabelle& tabelle, const string& id)             :tabelle(tabelle), id(id)       {        }        const spparametertabelle& tabelle;       string id; }; 

variant 2:

struct partabspaltedata {       partabspaltedata(const spparametertabelle& tabelle, const string& id)             :id(id)       {             // causes memory leak             tabelle2 = tabelle;       }        spparametertabelle tabelle2;       string id; }; 

have checked, not have cyclic shared pointer references?

for example:

class {   public: shared_ptr<a> x; };  shared_ptr<a> a1(new a()); shared_ptr<a> a2(new a()); a1->x = a2; a2->x = a1; 

here a1 , a2 never released, because have pointers each other keeps them alive.

so in case check if spparametertabelle has reference on partabspaltedata or if there possibility cyclic reference.  


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -