{"action":"created","comment":{"url":"https://api.github.com/repos/dartsim/dart/pulls/comments/32134878","id":32134878,"diff_hunk":"@@ -74,11 +76,49 @@ World::~World()\n   delete mConstraintSolver;\n   delete mRecording;\n \n-  for (std::vector<dynamics::Skeleton*>::const_iterator it = mSkeletons.begin();\n-       it != mSkeletons.end(); ++it)\n+  for(common::Connection& connection : mNameConnectionsForSkeletons)\n+    connection.disconnect();\n+\n+  for(common::Connection& connection : mNameConnectionsForFrames)\n+    connection.disconnect();\n+}\n+\n+//==============================================================================\n+WorldPtr World::clone() const\n+{\n+  WorldPtr worldClone(new World(mName));\n+\n+  worldClone->setGravity(mGravity);\n+  worldClone->setTimeStep(mTimeStep);\n+\n+  // Clone and add each Skeleton\n+  for(size_t i=0; i<mSkeletons.size(); ++i)\n+  {\n+    worldClone->addSkeleton(mSkeletons[i]->clone());\n+  }\n+\n+  // Clone and add each SimpleFrame\n+  for(size_t i=0; i<mFrames.size(); ++i)\n+  {\n+    worldClone->addFrame(mFrames[i]->clone(mFrames[i]->getParentFrame()));\n+  }\n+\n+  // For each newly cloned SimpleFrame, try to make its parent Frame be one of\n+  // the new clones if there is a match. This is meant to minimize any possible\n+  // interdependencies between the kinematics of different worlds.\n+  for(size_t i=0; i<worldClone->getNumFrames(); ++i)\n   {\n-    delete (*it);\n+    dynamics::Frame* current_parent =\n+        worldClone->getFrame(i)->getParentFrame();\n+\n+    dynamics::SimpleFramePtr parent_candidate =\n+        worldClone->getFrame(current_parent->getName());\n+\n+    if(parent_candidate)\n+      worldClone->getFrame(i)->setParentFrame(parent_candidate.get());","path":"dart/simulation/World.cpp","position":68,"original_position":68,"commit_id":"6094b7725648331ad17776d64124e611e7beecf2","original_commit_id":"6094b7725648331ad17776d64124e611e7beecf2","user":{"login":"jslee02","id":4038467,"avatar_url":"https://avatars.githubusercontent.com/u/4038467?v=3","gravatar_id":"","url":"https://api.github.com/users/jslee02","html_url":"https://github.com/jslee02","followers_url":"https://api.github.com/users/jslee02/followers","following_url":"https://api.github.com/users/jslee02/following{/other_user}","gists_url":"https://api.github.com/users/jslee02/gists{/gist_id}","starred_url":"https://api.github.com/users/jslee02/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jslee02/subscriptions","organizations_url":"https://api.github.com/users/jslee02/orgs","repos_url":"https://api.github.com/users/jslee02/repos","events_url":"https://api.github.com/users/jslee02/events{/privacy}","received_events_url":"https://api.github.com/users/jslee02/received_events","type":"User","site_admin":false},"body":"> It's more like, a SimpleFrame isn't necessarily tied to a World at all.\r\n\r\nI understand it more clearly now. I exclusion the case a SimpleFrame isn't tied to a World.\r\n\r\nlazy copying sounds interesting, and I agree with that the implementation would be somewhat challenging.\r\n\r\n> The big question would be whether changing a property in the original should also carry over to the existing clones of the original.\r\n\r\nIn my view, changing a property in the original shouldn't carry over to the clones, and they should be able to have different property values. It might be able to give a flag whether the property carry over to the clones, but keeping same property values in different world might be physically infeasible under certain circumstances. However, all the entities in the master world will always carry the same properties to all the dependent worlds. One use case I can imagine now is that we put entities for static environment to the master world and run different simulations in multiple worlds sharing the mast world. So whether carrying a property or not will be the differences between lazy copying and master world.","created_at":"2015-06-10T16:12:04Z","updated_at":"2015-06-10T16:12:04Z","html_url":"https://github.com/dartsim/dart/pull/369#discussion_r32134878","pull_request_url":"https://api.github.com/repos/dartsim/dart/pulls/369","_links":{"self":{"href":"https://api.github.com/repos/dartsim/dart/pulls/comments/32134878"},"html":{"href":"https://github.com/dartsim/dart/pull/369#discussion_r32134878"},"pull_request":{"href":"https://api.github.com/repos/dartsim/dart/pulls/369"}}},"pull_request":{"url":"https://api.github.com/repos/dartsim/dart/pulls/369","id":32000486,"html_url":"https://github.com/dartsim/dart/pull/369","diff_url":"https://github.com/dartsim/dart/pull/369.diff","patch_url":"https://github.com/dartsim/dart/pull/369.patch","issue_url":"https://api.github.com/repos/dartsim/dart/issues/369","number":369,"state":"open","locked":false,"title":"Eradicating memory leaks & making classes copy-safe and clonable","user":{"login":"mxgrey","id":1307217,"avatar_url":"https://avatars.githubusercontent.com/u/1307217?v=3","gravatar_id":"","url":"https://api.github.com/users/mxgrey","html_url":"https://github.com/mxgrey","followers_url":"https://api.github.com/users/mxgrey/followers","following_url":"https://api.github.com/users/mxgrey/following{/other_user}","gists_url":"https://api.github.com/users/mxgrey/gists{/gist_id}","starred_url":"https://api.github.com/users/mxgrey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxgrey/subscriptions","organizations_url":"https://api.github.com/users/mxgrey/orgs","repos_url":"https://api.github.com/users/mxgrey/repos","events_url":"https://api.github.com/users/mxgrey/events{/privacy}","received_events_url":"https://api.github.com/users/mxgrey/received_events","type":"User","site_admin":false},"body":"~~This is a premature pull request for review and discussion purposes, not ready to be merged yet~~\r\n\r\n### This pull request is ready for review\r\n\r\nThis branch and pull request are dedicated to removing memory leaks from DART as well introducing the ability to copy properties and create clones of objects. Spawning clones will be useful for making efficient multithreaded applications.\r\n\r\nThe changes being made here are pervasive, and some will require breaking the API, specifically the adoption of std::shared_ptr for the Shape and Skeleton classes.\r\n\r\nHere is a brief list of the conceptual changes:\r\n* BodyNode and Joint classes will all have a Properties struct that can be safely exchanged between different instances, and this struct will be used to standardize the constructors for the different types.\r\n* BodyNode and Joint instances will be fully managed by their Skeleton. BodyNode and Joint instances will only be creatable by the Skeleton class (the current procedure for assembling Skeletons will be deprecated) and they will be destroyed when the Skeleton class destructs\r\n* Shape instances and Skeleton instances will be treated as shared resources, and they will be managed by std::shared_ptr. BodyNodes and Joints are not shared resources because they are worthless/meaningless without being part of a single specific Skeleton.\r\n* It will be possible to clone Worlds and Skeletons.\r\n* Cloning a Skeleton entails creating a new Skeleton instance that is filled with new Joint instances and new BodyNodes instances which copy the properties of the original Skeleton's Joints and BodyNodes. Shape resources will be shared between Skeleton clones to minimize memory usage and copying overhead.\r\n* Cloning a World entails creating a new World instance that is filled with new Skeletons which are clones of the Skeletons of the original World.\r\n\r\n#### To be determined:\r\nIt would also be good to have a concept of a \"State\" to complement the \"Properties\" concept. I am still hashing out the details for how a State class would work, so suggestions are welcome. At the moment, I think the State should belong to the Skeleton, but it's not clear to me exactly how much information it should contain. It could either be just Generalized Position, Velocity, Acceleration, and Force vectors, or it could also include information like external forces.","created_at":"2015-03-26T09:27:02Z","updated_at":"2015-06-10T16:12:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6317730a3a662b0a3651fc1b9ca18374d56b8ad1","assignee":null,"milestone":{"url":"https://api.github.com/repos/dartsim/dart/milestones/6","html_url":"https://github.com/dartsim/dart/milestones/Release%20DART%205.0","labels_url":"https://api.github.com/repos/dartsim/dart/milestones/6/labels","id":679315,"number":6,"title":"Release DART 5.0","description":"Change plan and log:\r\n  * Math\r\n    * Add BSpline class (#300)\r\n  * Kinematics\r\n    * [Done] Add Frame class and auto-updating for forward kinematics (#319)\r\n    * Add Jacobian related API to Frame\r\n      * For example, getSpatialJacobian(relativeTo, inCoordinatesOf)\r\n  * Collision\r\n    * (Decouple dynamics from collision (dependency: kinematics <-- collision <-- dynamics))\r\n    * (Improve built-in collision detector -- support primitive shapes, mesh, and deformable mesh)\r\n    * Improve fcl collision detector -- merge fcl and fcl_mesh, support primitive shape collision, use broad-phase algorithm\r\n    * (Add more primitive shapes (sphere, capsule, and cone))\r\n  * Renderer / GUI\r\n    * [Done] Add the feature to plot 2D trajectories (#324)\r\n    * OpenSceneGraph gui\r\n  * Utils\r\n    * [Done] Fix a bug in loading WorldFile (#325)\r\n    * Improve Skel parser\r\n  * API\r\n    * Remove deprecated APIs in DART 4.x\r\n    * Eradicating memory leaks & making classes copy-safe and clonable (#369)\r\n  * ETC\r\n    * Drop dependency of tinyxml (used in urdf parser)\r\n    * (Improve numerical accuracy)\r\n    * Use code beautifier\r\n    * Minor improvements: #335\r\n\r\nTarget Gazebo version will be 6.0 (release date: 2015-07-27)\r\n\r\nSupported platforms (compilers)\r\n  * Ubuntu 14.04 LTS, 14.10, and 15.04\r\n    * Require [GCC 4.8](https://gcc.gnu.org/gcc-4.8/) or greater\r\n  * Windows \r\n    * Require [Visual Studio 2013](http://msdn.microsoft.com/en-us/library/dd831853.aspx) or greater\r\n    * (create additional repo that includes all the dependencies together)\r\n  * Mac OS X\r\n    * Require [Clang 3.3](http://llvm.org/releases/3.3/tools/clang/docs/ReleaseNotes.html) or greater","creator":{"login":"jslee02","id":4038467,"avatar_url":"https://avatars.githubusercontent.com/u/4038467?v=3","gravatar_id":"","url":"https://api.github.com/users/jslee02","html_url":"https://github.com/jslee02","followers_url":"https://api.github.com/users/jslee02/followers","following_url":"https://api.github.com/users/jslee02/following{/other_user}","gists_url":"https://api.github.com/users/jslee02/gists{/gist_id}","starred_url":"https://api.github.com/users/jslee02/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jslee02/subscriptions","organizations_url":"https://api.github.com/users/jslee02/orgs","repos_url":"https://api.github.com/users/jslee02/repos","events_url":"https://api.github.com/users/jslee02/events{/privacy}","received_events_url":"https://api.github.com/users/jslee02/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":53,"state":"open","created_at":"2014-06-03T15:46:59Z","updated_at":"2015-06-10T12:20:29Z","due_on":"2015-06-15T04:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/dartsim/dart/pulls/369/commits","review_comments_url":"https://api.github.com/repos/dartsim/dart/pulls/369/comments","review_comment_url":"https://api.github.com/repos/dartsim/dart/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dartsim/dart/issues/369/comments","statuses_url":"https://api.github.com/repos/dartsim/dart/statuses/6094b7725648331ad17776d64124e611e7beecf2","head":{"label":"dartsim:memory_management","ref":"memory_management","sha":"6094b7725648331ad17776d64124e611e7beecf2","user":{"login":"dartsim","id":4191609,"avatar_url":"https://avatars.githubusercontent.com/u/4191609?v=3","gravatar_id":"","url":"https://api.github.com/users/dartsim","html_url":"https://github.com/dartsim","followers_url":"https://api.github.com/users/dartsim/followers","following_url":"https://api.github.com/users/dartsim/following{/other_user}","gists_url":"https://api.github.com/users/dartsim/gists{/gist_id}","starred_url":"https://api.github.com/users/dartsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dartsim/subscriptions","organizations_url":"https://api.github.com/users/dartsim/orgs","repos_url":"https://api.github.com/users/dartsim/repos","events_url":"https://api.github.com/users/dartsim/events{/privacy}","received_events_url":"https://api.github.com/users/dartsim/received_events","type":"Organization","site_admin":false},"repo":{"id":2418592,"name":"dart","full_name":"dartsim/dart","owner":{"login":"dartsim","id":4191609,"avatar_url":"https://avatars.githubusercontent.com/u/4191609?v=3","gravatar_id":"","url":"https://api.github.com/users/dartsim","html_url":"https://github.com/dartsim","followers_url":"https://api.github.com/users/dartsim/followers","following_url":"https://api.github.com/users/dartsim/following{/other_user}","gists_url":"https://api.github.com/users/dartsim/gists{/gist_id}","starred_url":"https://api.github.com/users/dartsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dartsim/subscriptions","organizations_url":"https://api.github.com/users/dartsim/orgs","repos_url":"https://api.github.com/users/dartsim/repos","events_url":"https://api.github.com/users/dartsim/events{/privacy}","received_events_url":"https://api.github.com/users/dartsim/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dartsim/dart","description":"Dynamic Animation and Robotics Toolkit","fork":false,"url":"https://api.github.com/repos/dartsim/dart","forks_url":"https://api.github.com/repos/dartsim/dart/forks","keys_url":"https://api.github.com/repos/dartsim/dart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dartsim/dart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dartsim/dart/teams","hooks_url":"https://api.github.com/repos/dartsim/dart/hooks","issue_events_url":"https://api.github.com/repos/dartsim/dart/issues/events{/number}","events_url":"https://api.github.com/repos/dartsim/dart/events","assignees_url":"https://api.github.com/repos/dartsim/dart/assignees{/user}","branches_url":"https://api.github.com/repos/dartsim/dart/branches{/branch}","tags_url":"https://api.github.com/repos/dartsim/dart/tags","blobs_url":"https://api.github.com/repos/dartsim/dart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dartsim/dart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dartsim/dart/git/refs{/sha}","trees_url":"https://api.github.com/repos/dartsim/dart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dartsim/dart/statuses/{sha}","languages_url":"https://api.github.com/repos/dartsim/dart/languages","stargazers_url":"https://api.github.com/repos/dartsim/dart/stargazers","contributors_url":"https://api.github.com/repos/dartsim/dart/contributors","subscribers_url":"https://api.github.com/repos/dartsim/dart/subscribers","subscription_url":"https://api.github.com/repos/dartsim/dart/subscription","commits_url":"https://api.github.com/repos/dartsim/dart/commits{/sha}","git_commits_url":"https://api.github.com/repos/dartsim/dart/git/commits{/sha}","comments_url":"https://api.github.com/repos/dartsim/dart/comments{/number}","issue_comment_url":"https://api.github.com/repos/dartsim/dart/issues/comments{/number}","contents_url":"https://api.github.com/repos/dartsim/dart/contents/{+path}","compare_url":"https://api.github.com/repos/dartsim/dart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dartsim/dart/merges","archive_url":"https://api.github.com/repos/dartsim/dart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dartsim/dart/downloads","issues_url":"https://api.github.com/repos/dartsim/dart/issues{/number}","pulls_url":"https://api.github.com/repos/dartsim/dart/pulls{/number}","milestones_url":"https://api.github.com/repos/dartsim/dart/milestones{/number}","notifications_url":"https://api.github.com/repos/dartsim/dart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dartsim/dart/labels{/name}","releases_url":"https://api.github.com/repos/dartsim/dart/releases{/id}","created_at":"2011-09-19T21:53:51Z","updated_at":"2015-06-10T03:44:26Z","pushed_at":"2015-06-10T12:20:29Z","git_url":"git://github.com/dartsim/dart.git","ssh_url":"git@github.com:dartsim/dart.git","clone_url":"https://github.com/dartsim/dart.git","svn_url":"https://github.com/dartsim/dart","homepage":"http://dartsim.github.io/","size":109725,"stargazers_count":61,"watchers_count":61,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":47,"mirror_url":null,"open_issues_count":95,"forks":47,"open_issues":95,"watchers":61,"default_branch":"master"}},"base":{"label":"dartsim:master","ref":"master","sha":"d1ec56ce35e9b70d63e312560bfd5b1bbe071a30","user":{"login":"dartsim","id":4191609,"avatar_url":"https://avatars.githubusercontent.com/u/4191609?v=3","gravatar_id":"","url":"https://api.github.com/users/dartsim","html_url":"https://github.com/dartsim","followers_url":"https://api.github.com/users/dartsim/followers","following_url":"https://api.github.com/users/dartsim/following{/other_user}","gists_url":"https://api.github.com/users/dartsim/gists{/gist_id}","starred_url":"https://api.github.com/users/dartsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dartsim/subscriptions","organizations_url":"https://api.github.com/users/dartsim/orgs","repos_url":"https://api.github.com/users/dartsim/repos","events_url":"https://api.github.com/users/dartsim/events{/privacy}","received_events_url":"https://api.github.com/users/dartsim/received_events","type":"Organization","site_admin":false},"repo":{"id":2418592,"name":"dart","full_name":"dartsim/dart","owner":{"login":"dartsim","id":4191609,"avatar_url":"https://avatars.githubusercontent.com/u/4191609?v=3","gravatar_id":"","url":"https://api.github.com/users/dartsim","html_url":"https://github.com/dartsim","followers_url":"https://api.github.com/users/dartsim/followers","following_url":"https://api.github.com/users/dartsim/following{/other_user}","gists_url":"https://api.github.com/users/dartsim/gists{/gist_id}","starred_url":"https://api.github.com/users/dartsim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dartsim/subscriptions","organizations_url":"https://api.github.com/users/dartsim/orgs","repos_url":"https://api.github.com/users/dartsim/repos","events_url":"https://api.github.com/users/dartsim/events{/privacy}","received_events_url":"https://api.github.com/users/dartsim/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dartsim/dart","description":"Dynamic Animation and Robotics Toolkit","fork":false,"url":"https://api.github.com/repos/dartsim/dart","forks_url":"https://api.github.com/repos/dartsim/dart/forks","keys_url":"https://api.github.com/repos/dartsim/dart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dartsim/dart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dartsim/dart/teams","hooks_url":"https://api.github.com/repos/dartsim/dart/hooks","issue_events_url":"https://api.github.com/repos/dartsim/dart/issues/events{/number}","events_url":"https://api.github.com/repos/dartsim/dart/events","assignees_url":"https://api.github.com/repos/dartsim/dart/assignees{/user}","branches_url":"https://api.github.com/repos/dartsim/dart/branches{/branch}","tags_url":"https://api.github.com/repos/dartsim/dart/tags","blobs_url":"https://api.github.com/repos/dartsim/dart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dartsim/dart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dartsim/dart/git/refs{/sha}","trees_url":"https://api.github.com/repos/dartsim/dart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dartsim/dart/statuses/{sha}","languages_url":"https://api.github.com/repos/dartsim/dart/languages","stargazers_url":"https://api.github.com/repos/dartsim/dart/stargazers","contributors_url":"https://api.github.com/repos/dartsim/dart/contributors","subscribers_url":"https://api.github.com/repos/dartsim/dart/subscribers","subscription_url":"https://api.github.com/repos/dartsim/dart/subscription","commits_url":"https://api.github.com/repos/dartsim/dart/commits{/sha}","git_commits_url":"https://api.github.com/repos/dartsim/dart/git/commits{/sha}","comments_url":"https://api.github.com/repos/dartsim/dart/comments{/number}","issue_comment_url":"https://api.github.com/repos/dartsim/dart/issues/comments{/number}","contents_url":"https://api.github.com/repos/dartsim/dart/contents/{+path}","compare_url":"https://api.github.com/repos/dartsim/dart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dartsim/dart/merges","archive_url":"https://api.github.com/repos/dartsim/dart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dartsim/dart/downloads","issues_url":"https://api.github.com/repos/dartsim/dart/issues{/number}","pulls_url":"https://api.github.com/repos/dartsim/dart/pulls{/number}","milestones_url":"https://api.github.com/repos/dartsim/dart/milestones{/number}","notifications_url":"https://api.github.com/repos/dartsim/dart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dartsim/dart/labels{/name}","releases_url":"https://api.github.com/repos/dartsim/dart/releases{/id}","created_at":"2011-09-19T21:53:51Z","updated_at":"2015-06-10T03:44:26Z","pushed_at":"2015-06-10T12:20:29Z","git_url":"git://github.com/dartsim/dart.git","ssh_url":"git@github.com:dartsim/dart.git","clone_url":"https://github.com/dartsim/dart.git","svn_url":"https://github.com/dartsim/dart","homepage":"http://dartsim.github.io/","size":109725,"stargazers_count":61,"watchers_count":61,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":47,"mirror_url":null,"open_issues_count":95,"forks":47,"open_issues":95,"watchers":61,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dartsim/dart/pulls/369"},"html":{"href":"https://github.com/dartsim/dart/pull/369"},"issue":{"href":"https://api.github.com/repos/dartsim/dart/issues/369"},"comments":{"href":"https://api.github.com/repos/dartsim/dart/issues/369/comments"},"review_comments":{"href":"https://api.github.com/repos/dartsim/dart/pulls/369/comments"},"review_comment":{"href":"https://api.github.com/repos/dartsim/dart/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dartsim/dart/pulls/369/commits"},"statuses":{"href":"https://api.github.com/repos/dartsim/dart/statuses/6094b7725648331ad17776d64124e611e7beecf2"}}}}