From 48dcd5d7ff6d0b8ee23bc894dd8f3d234b5ad334 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 27 Apr 2020 18:32:22 +0200 Subject: [PATCH] Memory cleaning --- td/telegram/ContactsManager.cpp | 6 ++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/StickersManager.cpp | 16 ++++++++++++++++ td/telegram/StickersManager.h | 2 ++ td/telegram/Td.cpp | 4 ++++ td/telegram/WebPagesManager.cpp | 7 +++++++ td/telegram/WebPagesManager.h | 2 ++ 7 files changed, 39 insertions(+) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index fdc7e98b..cdc704f9 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13556,4 +13556,10 @@ void ContactsManager::get_current_state(vector &user); static ChatId get_chat_id(const tl_object_ptr &chat); static ChannelId get_channel_id(const tl_object_ptr &chat); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 33509865..bfcebda0 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -6178,4 +6178,20 @@ void StickersManager::get_current_state(vector convert_sticker_set_ids(const vector &sticker_set_ids); static vector convert_sticker_set_ids(const vector &sticker_set_ids); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 43cef2e7..046131e5 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5022,6 +5022,10 @@ void Td::on_request(uint64 id, td_api::getDatabaseStatistics &request) { } void Td::on_request(uint64 id, td_api::optimizeStorage &request) { + contacts_manager_->memory_cleanup(); + web_pages_manager_->memory_cleanup(); + stickers_manager_->memory_cleanup(); + std::vector file_types; for (auto &file_type : request.file_types_) { if (file_type == nullptr) { diff --git a/td/telegram/WebPagesManager.cpp b/td/telegram/WebPagesManager.cpp index 55d5ecd9..5883ea0a 100644 --- a/td/telegram/WebPagesManager.cpp +++ b/td/telegram/WebPagesManager.cpp @@ -1691,4 +1691,11 @@ vector WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c return result; } +void WebPagesManager::memory_cleanup() { +// web_pages_.clear(); +// web_page_messages_.clear(); +// got_web_page_previews_.clear(); +// url_to_web_page_id_.clear(); +// url_to_file_source_id_.clear(); +} } // namespace td diff --git a/td/telegram/WebPagesManager.h b/td/telegram/WebPagesManager.h index 8b80a7b9..c938c1ce 100644 --- a/td/telegram/WebPagesManager.h +++ b/td/telegram/WebPagesManager.h @@ -37,6 +37,8 @@ class WebPagesManager : public Actor { public: WebPagesManager(Td *td, ActorShared<> parent); + void memory_cleanup(); + WebPagesManager(const WebPagesManager &) = delete; WebPagesManager &operator=(const WebPagesManager &) = delete; WebPagesManager(WebPagesManager &&) = delete;