in the follow code memory leak happened, I have my doubt about that. in the test() fun:
#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
class parent;
class children;
typedef boost::shared_ptr<parent> parent_ptr;
typedef boost::shared_ptr<children> children_ptr;
class parent
{
public:
~parent() { std::cout <<"destroying parent\n"; }
public:
children_ptr children;
};
class children
{
public:
~children() { std::cout <<"destroying children\n"; }
public:
parent_ptr parent;
};
void test()
{
parent_ptr father(new parent());
children_ptr son(new children);
father->children = son;// parent_ptr_count=1, children_ptr_count=2
son->parent = father;// parent_ptr_count=2, children_ptr_count=2
//1,2,3 See the note below
}
void main()
{
std::cout<<"begin test...\n";
test();
std::cout<<"end test.\n";
}
// childern_ptr pop from stack, I think the childern_ptr_count-- and parent_ptr_count--
// parent_ptr pop from stack, I think the childern_ptr_count-- and parent_ptr_count--
// but in fact, it didn't do that, why?
I hope someone can help me, thank you very much.