deprecate shared pointer to parent link to fix memory leak

This commit is contained in:
meeussen 2009-10-05 22:00:53 +00:00
parent 379c125184
commit 807338a5a0
4 changed files with 24 additions and 1 deletions

View File

@ -30,6 +30,10 @@ rosbuild_add_boost_directories()
rosbuild_add_executable(urdf_check src/urdf_check.cpp)
target_link_libraries(urdf_check ${PROJECT_NAME})
rosbuild_add_executable(mem_test test/memtest.cpp)
target_link_libraries(mem_test ${PROJECT_NAME})
rosbuild_add_executable(test_parser EXCLUDE_FROM_ALL test/test_robot_model_parser.cpp)
rosbuild_add_gtest_build_flags(test_parser)
target_link_libraries(test_parser ${PROJECT_NAME})

View File

@ -206,12 +206,16 @@ public:
/// every link can have one parent
boost::shared_ptr<Joint> parent_joint;
/// Get Parent Link throught the Parent Joint
boost::shared_ptr<Link> parent_link;
boost::shared_ptr<Link> parent_link __attribute__((deprecated)); // use getParent() instead
std::vector<boost::shared_ptr<Joint> > child_joints;
std::vector<boost::shared_ptr<Link> > child_links;
bool initXml(TiXmlElement* config);
boost::shared_ptr<Link> getParent() const
{return parent_link_.lock();};
void setParent(boost::shared_ptr<Link> parent);
void clear()
@ -228,6 +232,10 @@ public:
void setParentJoint(boost::shared_ptr<Joint> child);
void addChild(boost::shared_ptr<Link> child);
void addChildJoint(boost::shared_ptr<Joint> child);
private:
boost::weak_ptr<Link> parent_link_;
};

View File

@ -407,6 +407,7 @@ bool Link::initXml(TiXmlElement* config)
void Link::setParent(boost::shared_ptr<Link> parent)
{
this->parent_link = parent;
this->parent_link_ = parent;
ROS_DEBUG("set parent Link '%s' for Link '%s'", parent->name.c_str(), this->name.c_str());
}

10
urdf/test/memtest.cpp Normal file
View File

@ -0,0 +1,10 @@
#include <urdf/model.h>
#include <ros/ros.h>
int main(int argc, char** argv){
ros::init(argc, argv, "memtest");
while (ros::ok()){
urdf::Model urdf;
urdf.initFile(std::string(argv[1]));
}
}