diff --git a/apps/regression/store_controller.cpp b/apps/regression/store_controller.cpp index 64ce0087a..b61c92602 100644 --- a/apps/regression/store_controller.cpp +++ b/apps/regression/store_controller.cpp @@ -19,6 +19,15 @@ StoreController::StoreController(Responder * parentResponder, Store * store, But m_titleLayout[1] = new BaselineRelativeLayout(new StringLayout("Y", 1, KDText::FontSize::Small), new StringLayout("i", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); } +StoreController::~StoreController() { + for (int i = 0; i < 2; i++) { + if (m_titleLayout[i]) { + delete m_titleLayout[i]; + m_titleLayout[i] = nullptr; + } + } +} + void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { ::StoreController::willDisplayCellAtLocation(cell, i, j); if (cellAtLocationIsEditable(i, j)) { diff --git a/apps/regression/store_controller.h b/apps/regression/store_controller.h index 9e27bad66..84db3cda1 100644 --- a/apps/regression/store_controller.h +++ b/apps/regression/store_controller.h @@ -10,6 +10,7 @@ namespace Regression { class StoreController : public Shared::StoreController { public: StoreController(Responder * parentResponder, Store * store, ButtonRowController * header); + ~StoreController(); void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override; private: HighlightCell * titleCells(int index) override; diff --git a/apps/sequence/list/sequence_toolbox.cpp b/apps/sequence/list/sequence_toolbox.cpp index 40afb6234..4ff609384 100644 --- a/apps/sequence/list/sequence_toolbox.cpp +++ b/apps/sequence/list/sequence_toolbox.cpp @@ -13,6 +13,15 @@ SequenceToolbox::SequenceToolbox() : { } +SequenceToolbox::~SequenceToolbox() { + for (int i = 0; i < k_maxNumberOfDisplayedRows; i++) { + if (m_addedCellLayout[i]) { + delete m_addedCellLayout[i]; + m_addedCellLayout[i] = nullptr; + } + } +} + bool SequenceToolbox::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK && stackDepth() == 0) { int selectedRow = m_selectableTableView.selectedRow(); @@ -65,6 +74,12 @@ int SequenceToolbox::typeAtLocation(int i, int j) { } void SequenceToolbox::setExtraCells(const char * sequenceName, int recurrenceDepth) { + for (int i = 0; i < k_maxNumberOfDisplayedRows; i++) { + if (m_addedCellLayout[i]) { + delete m_addedCellLayout[i]; + m_addedCellLayout[i] = nullptr; + } + } m_numberOfAddedCells = recurrenceDepth; for (int j = 0; j < recurrenceDepth; j++) { m_addedCellLayout[j] = new BaselineRelativeLayout(new StringLayout(sequenceName, 1, KDText::FontSize::Large), new StringLayout((char *)(j == 0? "n" : "n+1"), strlen((char *)(j == 0? "n" : "n+1")), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); diff --git a/apps/sequence/list/sequence_toolbox.h b/apps/sequence/list/sequence_toolbox.h index 794d6140a..2fbe49a3b 100644 --- a/apps/sequence/list/sequence_toolbox.h +++ b/apps/sequence/list/sequence_toolbox.h @@ -8,6 +8,7 @@ namespace Sequence { class SequenceToolbox : public MathToolbox { public: SequenceToolbox(); + ~SequenceToolbox(); bool handleEvent(Ion::Events::Event event) override; int numberOfRows() override; HighlightCell * reusableCell(int index, int type) override; diff --git a/escher/include/escher/expression_view.h b/escher/include/escher/expression_view.h index 44c520676..bedfc08c1 100644 --- a/escher/include/escher/expression_view.h +++ b/escher/include/escher/expression_view.h @@ -22,6 +22,11 @@ public: void setAlignment(float horizontalAlignment, float verticalAlignment); KDSize minimalSizeForOptimalDisplay() override; private: + /* Warning: we do not need to delete the previous expression layout when + * deleting object or setting a new expression layout. Indeed, the expression + * layout is always possessed by a controller which only gives a pointer to + * the expression view (without cloning it). The named controller is then + * responsible for freeing the expression layout when required. */ Poincare::ExpressionLayout * m_expressionLayout; float m_horizontalAlignment; float m_verticalAlignment;