diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp index 80b89e91a5..63675f80f4 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiFormLayoutObjectEditor.cpp @@ -492,11 +492,25 @@ void caf::PdmUiFormLayoutObjectEditor::cleanupBeforeSettingPdmObject() m_groupBoxes.clear(); - for ( auto l : m_layouts ) - { - delete l; - l = nullptr; - } + // https://github.com/OPM/ResInsight/issues/9939 + // + // The following lines causes crash. m_layouts contains pointers to layouts that are invalid at this point. The + // m_layouts are created for widgets where the labels are located on top of the widget, and this option is rarely + // used. The crash happens on exit every time when a layout has been created. + // + // A crash has also happened during runtime, but is hard to reproduce. + // + // NB! There will be memory leak at this point, but the workaround allowing memory leak is considered OK on short + // term. Investigate and find a correct solution + // + /* + for ( auto l : m_layouts ) + { + delete l; + l = nullptr; + } + */ + m_layouts.clear(); }