From 9b21e5c7690d459f4c0f1f9cc82432f8e543bf5f Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 26 May 2014 21:42:51 +0200 Subject: [PATCH] [DEV] correction some internal memory leek --- sources/appl/BufferManager.cpp | 7 +-- sources/appl/Gui/BufferView.cpp | 25 +++++----- sources/appl/Gui/BufferView.h | 2 +- sources/appl/Gui/MainWindows.cpp | 6 ++- sources/appl/Gui/Search.cpp | 10 ++-- sources/appl/Highlight.cpp | 1 + sources/appl/TextPlugin.cpp | 2 +- sources/appl/TextPluginAutoIndent.cpp | 1 + sources/appl/TextPluginCopy.cpp | 1 + sources/appl/TextPluginCtags.cpp | 1 + sources/appl/TextPluginData.h | 6 ++- sources/appl/TextPluginHistory.cpp | 4 +- sources/appl/TextPluginHistory.h | 2 +- sources/appl/TextPluginManager.cpp | 65 +++++++++++-------------- sources/appl/TextPluginMultiLineTab.cpp | 1 + sources/appl/TextPluginRmLine.cpp | 1 + sources/appl/TextPluginSelectAll.cpp | 1 + 17 files changed, 74 insertions(+), 62 deletions(-) diff --git a/sources/appl/BufferManager.cpp b/sources/appl/BufferManager.cpp index bbac042..c4f86a3 100644 --- a/sources/appl/BufferManager.cpp +++ b/sources/appl/BufferManager.cpp @@ -72,12 +72,13 @@ void appl::BufferManager::setBufferSelected(ewol::object::Shared _ sendMultiCast(appl::MsgSelectChange, ""); } -void appl::BufferManager::onObjectRemove(const ewol::object::Shared& _removeObject) { - if (m_bufferSelected == _removeObject) { +void appl::BufferManager::onObjectRemove(const ewol::object::Shared& _object) { + ewol::Resource::onObjectRemove(_object); + if (m_bufferSelected == _object) { setBufferSelected(NULL); } for (auto it(m_list.begin()); it!=m_list.end(); ++it) { - if (*it != _removeObject) { + if (*it != _object) { continue; } m_list.erase(it); diff --git a/sources/appl/Gui/BufferView.cpp b/sources/appl/Gui/BufferView.cpp index 88ccf11..4119cff 100644 --- a/sources/appl/Gui/BufferView.cpp +++ b/sources/appl/Gui/BufferView.cpp @@ -218,18 +218,21 @@ void BufferView::onReceiveMessage(const ewol::object::Message& _msg) { } } -void BufferView::onObjectRemove(const ewol::object::Shared& _removeObject) { - ewol::widget::List::onObjectRemove(_removeObject); - for (int32_t iii=0; iii& _object) { + ewol::widget::List::onObjectRemove(_object); + auto it(m_list.begin()); + while (it != m_list.end()) { + if ( *it != nullptr + && (*it)->m_buffer == _object) { + m_list.erase(it); + markToRedraw(); + it = m_list.begin(); + } else { + ++it; } - if (m_list[iii]->m_buffer != _removeObject) { - continue; - } - m_list.erase(m_list.begin()+iii); - markToRedraw(); - return; + } + if (m_bufferManager == _object) { + m_bufferManager.reset(); } } diff --git a/sources/appl/Gui/BufferView.h b/sources/appl/Gui/BufferView.h index 8e308d6..e8807ab 100644 --- a/sources/appl/Gui/BufferView.h +++ b/sources/appl/Gui/BufferView.h @@ -54,7 +54,7 @@ class BufferView : public ewol::widget::List { ~BufferView(); // Derived function virtual void onReceiveMessage(const ewol::object::Message& _msg); - virtual void onObjectRemove(const ewol::object::Shared& _removeObject); + virtual void onObjectRemove(const ewol::object::Shared& _object); private: bool m_openOrderMode; //!< true if the order is the opening order mode, otherwise, Alphabetic order protected: diff --git a/sources/appl/Gui/MainWindows.cpp b/sources/appl/Gui/MainWindows.cpp index b65603b..d5c82a8 100644 --- a/sources/appl/Gui/MainWindows.cpp +++ b/sources/appl/Gui/MainWindows.cpp @@ -133,18 +133,21 @@ MainWindows::MainWindows() { m_bufferManager = appl::BufferManager::keep(); mySizerVert = ewol::object::makeShared(new ewol::widget::Sizer(ewol::widget::Sizer::modeVert)); + mySizerVert->setName("plop 1111111"); setSubWidget(mySizerVert); mySizerHori = ewol::object::makeShared(new ewol::widget::Sizer(ewol::widget::Sizer::modeHori)); + mySizerHori->setName("plop 222222222"); mySizerVert->subWidgetAdd(mySizerHori); myBufferView = ewol::object::makeShared(new BufferView()); + myBufferView->setName("plop 3333333"); myBufferView->setExpand(bvec2(false,true)); myBufferView->setFill(bvec2(true,true)); mySizerHori->subWidgetAdd(myBufferView); mySizerVert2 = ewol::object::makeShared(new ewol::widget::Sizer(ewol::widget::Sizer::modeVert)); mySizerHori->subWidgetAdd(mySizerVert2); - + mySizerVert2->setName("plop 4444444"); // main buffer Area : #if defined(__TARGET_OS__Android) myTextView = ewol::object::makeShared(new appl::TextViewer("FreeMono;DejaVuSansMono;FreeSerif", 16)); @@ -166,6 +169,7 @@ MainWindows::MainWindows() { mySizerVert2->subWidgetAdd(mySearch); mySizerHori = ewol::object::makeShared(new ewol::widget::Sizer(ewol::widget::Sizer::modeHori)); + mySizerHori->setName("plop 555555"); mySizerVert->subWidgetAdd(mySizerHori); myMenu = ewol::object::makeShared(new ewol::widget::Menu()); diff --git a/sources/appl/Gui/Search.cpp b/sources/appl/Gui/Search.cpp index 7610af9..8ab85a0 100644 --- a/sources/appl/Gui/Search.cpp +++ b/sources/appl/Gui/Search.cpp @@ -162,15 +162,15 @@ void Search::onReceiveMessage(const ewol::object::Message& _msg) { } } -void Search::onObjectRemove(const ewol::object::Shared _removeObject) { - ewol::widget::Composer::onObjectRemove(_removeObject); - if (_removeObject == m_searchEntry) { +void Search::onObjectRemove(const ewol::object::Shared _object) { + ewol::widget::Composer::onObjectRemove(_object); + if (_object == m_searchEntry) { m_searchEntry.reset(); } - if (_removeObject == m_replaceEntry) { + if (_object == m_replaceEntry) { m_replaceEntry.reset(); } - if (_removeObject == m_viewerManager) { + if (_object == m_viewerManager) { m_viewerManager.reset(); } } diff --git a/sources/appl/Highlight.cpp b/sources/appl/Highlight.cpp index fa5dfc3..18b9607 100644 --- a/sources/appl/Highlight.cpp +++ b/sources/appl/Highlight.cpp @@ -38,6 +38,7 @@ void appl::Highlight::parseRules(exml::Element* _child, appl::Highlight::Highlight(const std::string& _xmlFilename, const std::string& _colorFile) : ewol::Resource(_xmlFilename), m_typeName("") { + addObjectType("appl::Highlight"); // keep color propertiy file : m_paintingProperties = appl::GlyphPainting::keep(_colorFile); diff --git a/sources/appl/TextPlugin.cpp b/sources/appl/TextPlugin.cpp index 4458569..359b725 100644 --- a/sources/appl/TextPlugin.cpp +++ b/sources/appl/TextPlugin.cpp @@ -23,7 +23,7 @@ appl::TextViewerPlugin::TextViewerPlugin() : m_activateOnRemove(false), m_activateOnReceiveMessage(false), m_activateOnCursorMove(false) { - + addObjectType("appl::TextViewerPlugin"); } appl::TextViewerPlugin::~TextViewerPlugin() { diff --git a/sources/appl/TextPluginAutoIndent.cpp b/sources/appl/TextPluginAutoIndent.cpp index d6ea185..1cfb982 100644 --- a/sources/appl/TextPluginAutoIndent.cpp +++ b/sources/appl/TextPluginAutoIndent.cpp @@ -17,6 +17,7 @@ appl::TextPluginAutoIndent::TextPluginAutoIndent() { m_activateOnEventEntry = true; + addObjectType("appl::TextPluginAutoIndent"); } bool appl::TextPluginAutoIndent::onEventEntry(appl::TextViewer& _textDrawer, diff --git a/sources/appl/TextPluginCopy.cpp b/sources/appl/TextPluginCopy.cpp index 439c908..b4cd9ba 100644 --- a/sources/appl/TextPluginCopy.cpp +++ b/sources/appl/TextPluginCopy.cpp @@ -17,6 +17,7 @@ appl::TextPluginCopy::TextPluginCopy() { m_activateOnReceiveMessage = true; + addObjectType("appl::TextPluginCopy"); } void appl::TextPluginCopy::onPluginEnable(appl::TextViewer& _textDrawer) { diff --git a/sources/appl/TextPluginCtags.cpp b/sources/appl/TextPluginCtags.cpp index f3d21ed..f595b95 100644 --- a/sources/appl/TextPluginCtags.cpp +++ b/sources/appl/TextPluginCtags.cpp @@ -25,6 +25,7 @@ appl::TextPluginCtags::TextPluginCtags() : m_activateOnReceiveMessage = true; // load buffer manager: m_bufferManager = appl::BufferManager::keep(); + addObjectType("appl::TextPluginCtags"); } appl::TextPluginCtags::~TextPluginCtags() { diff --git a/sources/appl/TextPluginData.h b/sources/appl/TextPluginData.h index 9cf19ab..54692bd 100644 --- a/sources/appl/TextPluginData.h +++ b/sources/appl/TextPluginData.h @@ -20,6 +20,7 @@ namespace appl { public: TextViewerPluginData() { // nothing to do ... + addObjectType("appl::TextViewerPluginData"); } virtual ~TextViewerPluginData() { for (size_t iii = 0; iii < m_specificData.size() ; ++iii) { @@ -115,9 +116,10 @@ namespace appl { return; }; public: - virtual void onObjectRemove(const ewol::object::Shared& _removeObject) { + virtual void onObjectRemove(const ewol::object::Shared& _object) { + appl::TextViewerPlugin::onObjectRemove(_object); for (auto it(m_specificData.begin()); it != m_specificData.end(); ++it) { - if (it->first == _removeObject) { + if (it->first == _object) { m_specificData.erase(it); it = m_specificData.begin(); } diff --git a/sources/appl/TextPluginHistory.cpp b/sources/appl/TextPluginHistory.cpp index af6c7c5..96734d9 100644 --- a/sources/appl/TextPluginHistory.cpp +++ b/sources/appl/TextPluginHistory.cpp @@ -20,6 +20,7 @@ appl::TextPluginHistory::TextPluginHistory() { m_activateOnWrite = true; m_activateOnReplace = true; m_activateOnRemove = true; + addObjectType("appl::TextPluginHistory"); } void appl::TextPluginHistory::onPluginEnable(appl::TextViewer& _textDrawer) { @@ -176,7 +177,8 @@ bool appl::TextPluginHistory::onRemove(appl::TextViewer& _textDrawer, } -void appl::TextPluginHistory::onObjectRemove(const ewol::object::Shared& _removeObject) { +void appl::TextPluginHistory::onObjectRemove(const ewol::object::Shared& _object) { + appl::TextViewerPluginData::onObjectRemove(_object); // TODO : Dependence with buffer removing ... } diff --git a/sources/appl/TextPluginHistory.h b/sources/appl/TextPluginHistory.h index c3f29ad..ff99d5c 100644 --- a/sources/appl/TextPluginHistory.h +++ b/sources/appl/TextPluginHistory.h @@ -67,7 +67,7 @@ namespace appl { void clearRedo(appl::PluginHistoryData& _data); void clearUndo(appl::PluginHistoryData& _data); public: - virtual void onObjectRemove(const ewol::object::Shared& _removeObject); + virtual void onObjectRemove(const ewol::object::Shared& _object); }; }; diff --git a/sources/appl/TextPluginManager.cpp b/sources/appl/TextPluginManager.cpp index 14fa69e..30a5839 100644 --- a/sources/appl/TextPluginManager.cpp +++ b/sources/appl/TextPluginManager.cpp @@ -19,8 +19,8 @@ #undef __class__ #define __class__ "textPluginManager" -static std::vector>& getList() { - static std::vector> s_list; +static std::list>& getList() { + static std::list> s_list; return s_list; } static std::vector>& getListOnEventEntry() { @@ -107,31 +107,30 @@ void appl::textPluginManager::addPlugin(const ewol::object::SharedonPluginEnable(_widget); + it->onPluginEnable(_widget); } } void appl::textPluginManager::disconnect(appl::TextViewer& _widget) { - for (int32_t iii=0; iiionPluginDisable(_widget); + it->onPluginDisable(_widget); } } bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer, const ewol::event::Entry& _event) { - std::vector>& list = getListOnEventEntry(); - for (int32_t iii=0; iiionEventEntry(_textDrawer, _event) == true ) { + if (it->onEventEntry(_textDrawer, _event) == true ) { return true; } } @@ -140,12 +139,11 @@ bool appl::textPluginManager::onEventEntry(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer, const ewol::event::Input& _event) { - std::vector>& list = getListOnEventInput(); - for (int32_t iii=0; iiionEventInput(_textDrawer, _event) == true ) { + if (it->onEventInput(_textDrawer, _event) == true ) { return true; } } @@ -155,12 +153,11 @@ bool appl::textPluginManager::onEventInput(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onWrite(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const std::string& _data) { - std::vector>& list = getListOnWrite(); - for (int32_t iii=0; iiionWrite(_textDrawer, _pos, _data) == true ) { + if (it->onWrite(_textDrawer, _pos, _data) == true ) { return true; } } @@ -171,12 +168,11 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const std::string& _data, const appl::Buffer::Iterator& _posEnd) { - std::vector>& list = getListOnReplace(); - for (int32_t iii=0; iiionReplace(_textDrawer, _pos, _data, _posEnd) == true ) { + if (it->onReplace(_textDrawer, _pos, _data, _posEnd) == true ) { return true; } } @@ -186,12 +182,11 @@ bool appl::textPluginManager::onReplace(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) { - std::vector>& list = getListOnRemove(); - for (int32_t iii=0; iiionRemove(_textDrawer, _pos, _posEnd) == true ) { + if (it->onRemove(_textDrawer, _pos, _posEnd) == true ) { return true; } } @@ -200,12 +195,11 @@ bool appl::textPluginManager::onRemove(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onReceiveMessage(appl::TextViewer& _textDrawer, const ewol::object::Message& _msg) { - std::vector>& list = getListOnReceiveMessage(); - for (int32_t iii=0; iiionReceiveMessage(_textDrawer, _msg) == true ) { + if (it->onReceiveMessage(_textDrawer, _msg) == true ) { return true; } } @@ -214,12 +208,11 @@ bool appl::textPluginManager::onReceiveMessage(appl::TextViewer& _textDrawer, bool appl::textPluginManager::onCursorMove(appl::TextViewer& _textDrawer, const appl::Buffer::Iterator& _pos) { - std::vector>& list = getListOnCursorMove(); - for (int32_t iii=0; iiionCursorMove(_textDrawer, _pos) == true ) { + if (it->onCursorMove(_textDrawer, _pos) == true ) { return true; } } diff --git a/sources/appl/TextPluginMultiLineTab.cpp b/sources/appl/TextPluginMultiLineTab.cpp index a4f0798..fd1de98 100644 --- a/sources/appl/TextPluginMultiLineTab.cpp +++ b/sources/appl/TextPluginMultiLineTab.cpp @@ -16,6 +16,7 @@ appl::TextPluginMultiLineTab::TextPluginMultiLineTab() { m_activateOnEventEntry = true; + addObjectType("appl::TextPluginMultiLineTab"); } bool appl::TextPluginMultiLineTab::onEventEntry(appl::TextViewer& _textDrawer, diff --git a/sources/appl/TextPluginRmLine.cpp b/sources/appl/TextPluginRmLine.cpp index d2694b2..aa36344 100644 --- a/sources/appl/TextPluginRmLine.cpp +++ b/sources/appl/TextPluginRmLine.cpp @@ -17,6 +17,7 @@ appl::TextPluginRmLine::TextPluginRmLine() { m_activateOnReceiveMessage = true; + addObjectType("appl::TextPluginRmLine"); } void appl::TextPluginRmLine::onPluginEnable(appl::TextViewer& _textDrawer) { diff --git a/sources/appl/TextPluginSelectAll.cpp b/sources/appl/TextPluginSelectAll.cpp index 2871dea..4045dca 100644 --- a/sources/appl/TextPluginSelectAll.cpp +++ b/sources/appl/TextPluginSelectAll.cpp @@ -17,6 +17,7 @@ appl::TextPluginSelectAll::TextPluginSelectAll() { m_activateOnReceiveMessage = true; + addObjectType("appl::TextPluginSelectAll"); } static const char* eventSelectAll = "plugin-select-all";