Browse Source

ModuleParams: remove parent in destructor

This allows for dynamic deletion of children objects (in most cases this
is not used).

Uses ~100B memory.
master
Beat Küng 3 years ago committed by Daniel Agar
parent
commit
810d2e9497
  1. 8
      platforms/common/include/px4_platform_common/module_params.h

8
platforms/common/include/px4_platform_common/module_params.h

@ -61,9 +61,14 @@ public: @@ -61,9 +61,14 @@ public:
if (parent) {
parent->_children.add(this);
}
_parent = parent;
}
virtual ~ModuleParams() = default;
virtual ~ModuleParams()
{
if (_parent) { _parent->_children.remove(this); }
}
// Disallow copy construction and move assignment.
ModuleParams(const ModuleParams &) = delete;
@ -93,4 +98,5 @@ protected: @@ -93,4 +98,5 @@ protected:
private:
/** @list _children The module parameter list of inheriting classes. */
List<ModuleParams *> _children;
ModuleParams *_parent{nullptr};
};

Loading…
Cancel
Save