Potential for smart pointer reference loops in physics::Base

Create issue
Issue #1142 new
Steven Peters created an issue

The physics::Base class stores the objects in the world as a hierarchy (Model, Link, Collision, Joint, etc.). Each objects stores a vector of smart pointers to its children as well as a smart pointer to its parent. This has the potential to create smart pointer reference loops. We should consider changing the parent pointer to a weak shared pointer.

Comments (7)

  1. Ian Chen

    +1 on using more of weak pointers. Visuals also suffer from this. In the past I've run into a few issues caused by objects not being deleted when they should.

  2. Steven Peters reporter

    There's also a lot of WorldPtr smart pointers:

    $ grep 'WorldPtr world;' `find . | grep hh$` | sort
    ./gazebo/gui/ModelBuilderWidget.hh:      private: physics::WorldPtr world;
    ./gazebo/physics/Base.hh:      protected: WorldPtr world;
    ./gazebo/physics/Contact.hh:      public: WorldPtr world;
    ./gazebo/physics/ContactManager.hh:      private: WorldPtr world;
    ./gazebo/physics/Gripper.hh:      private: physics::WorldPtr world;
    ./gazebo/physics/PhysicsEngine.hh:      protected: WorldPtr world;
    ./gazebo/physics/WorldState.hh:      private: WorldPtr world;
    ./gazebo/sensors/Sensor.hh:      protected: gazebo::physics::WorldPtr world;
    ./plugins/ArrangePlugin.hh:    protected: physics::WorldPtr world;
    ./plugins/events/EventSource.hh:    protected: physics::WorldPtr world;
    ./plugins/events/SimEventsPlugin.hh:    private: physics::WorldPtr world;
    ./plugins/HydraDemoPlugin.hh:    private: physics::WorldPtr world;
    ./plugins/ImuSensorPlugin.hh:    private: physics::WorldPtr world;
    ./plugins/JointTrajectoryPlugin.hh:    private: physics::WorldPtr world;
    ./plugins/LiftDragPlugin.hh:    protected: physics::WorldPtr world;
    ./plugins/MudPlugin.hh:    private: physics::WorldPtr world;
    ./plugins/RayPlugin.hh:    protected: physics::WorldPtr world;
    ./plugins/RubblePlugin.hh:    private: physics::WorldPtr world;
    ./plugins/TransporterPluginPrivate.hh:    public: physics::WorldPtr world;
    ./test/plugins/Issue1208Plugin.hh:    private: physics::WorldPtr world;
    
  3. Log in to comment