From 810d2e9497a121be594206f91ebf1b4e00216be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Wed, 8 Sep 2021 10:05:13 +0200 Subject: [PATCH] ModuleParams: remove parent in destructor This allows for dynamic deletion of children objects (in most cases this is not used). Uses ~100B memory. --- .../common/include/px4_platform_common/module_params.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platforms/common/include/px4_platform_common/module_params.h b/platforms/common/include/px4_platform_common/module_params.h index d2e518f0ce..5a3d085fe7 100644 --- a/platforms/common/include/px4_platform_common/module_params.h +++ b/platforms/common/include/px4_platform_common/module_params.h @@ -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: private: /** @list _children The module parameter list of inheriting classes. */ List _children; + ModuleParams *_parent{nullptr}; };