Clean memory only if needed
This commit is contained in:
parent
062d1c2f5a
commit
ce9a9ebbf9
@ -11,6 +11,7 @@
|
|||||||
#include "td/telegram/DialogId.h"
|
#include "td/telegram/DialogId.h"
|
||||||
#include "td/telegram/Document.h"
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/FileReferenceManager.h"
|
#include "td/telegram/FileReferenceManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
#include "td/telegram/files/FileType.h"
|
#include "td/telegram/files/FileType.h"
|
||||||
@ -146,9 +147,11 @@ AnimationsManager::AnimationsManager(Td *td, ActorShared<> parent) : td_(td), pa
|
|||||||
|
|
||||||
void AnimationsManager::tear_down() {
|
void AnimationsManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32 AnimationsManager::get_animation_duration(FileId file_id) const {
|
int32 AnimationsManager::get_animation_duration(FileId file_id) const {
|
||||||
auto it = animations_.find(file_id);
|
auto it = animations_.find(file_id);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "td/telegram/InputGroupCallId.h"
|
#include "td/telegram/InputGroupCallId.h"
|
||||||
#include "td/telegram/logevent/LogEvent.h"
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
#include "td/telegram/logevent/LogEventHelper.h"
|
#include "td/telegram/logevent/LogEventHelper.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/MessageTtlSetting.h"
|
#include "td/telegram/MessageTtlSetting.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
@ -3450,9 +3451,11 @@ ContactsManager::~ContactsManager() = default;
|
|||||||
|
|
||||||
void ContactsManager::tear_down() {
|
void ContactsManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UserId ContactsManager::load_my_id() {
|
UserId ContactsManager::load_my_id() {
|
||||||
auto id_string = G()->td_db()->get_binlog_pmc()->get("my_id");
|
auto id_string = G()->td_db()->get_binlog_pmc()->get("my_id");
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/MessageId.h"
|
#include "td/telegram/MessageId.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/net/NetQuery.h"
|
#include "td/telegram/net/NetQuery.h"
|
||||||
@ -478,9 +479,11 @@ GroupCallManager::~GroupCallManager() = default;
|
|||||||
|
|
||||||
void GroupCallManager::tear_down() {
|
void GroupCallManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GroupCallManager::memory_cleanup() {
|
void GroupCallManager::memory_cleanup() {
|
||||||
memory_cleanup(false);
|
memory_cleanup(false);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "td/telegram/Contact.h"
|
#include "td/telegram/Contact.h"
|
||||||
#include "td/telegram/ContactsManager.h"
|
#include "td/telegram/ContactsManager.h"
|
||||||
#include "td/telegram/Document.h"
|
#include "td/telegram/Document.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/DocumentsManager.h"
|
#include "td/telegram/DocumentsManager.h"
|
||||||
#include "td/telegram/files/FileManager.h"
|
#include "td/telegram/files/FileManager.h"
|
||||||
#include "td/telegram/files/FileType.h"
|
#include "td/telegram/files/FileType.h"
|
||||||
@ -166,9 +167,11 @@ InlineQueriesManager::InlineQueriesManager(Td *td, ActorShared<> parent) : td_(t
|
|||||||
|
|
||||||
void InlineQueriesManager::tear_down() {
|
void InlineQueriesManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InlineQueriesManager::on_drop_inline_query_result_timeout_callback(void *inline_queries_manager_ptr,
|
void InlineQueriesManager::on_drop_inline_query_result_timeout_callback(void *inline_queries_manager_ptr,
|
||||||
int64 query_hash) {
|
int64 query_hash) {
|
||||||
|
@ -85,7 +85,13 @@ void MemoryManager::tear_down() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MemoryManager::can_manage_memory() const {
|
bool MemoryManager::can_manage_memory() const {
|
||||||
return td_->auth_manager_->is_authorized() && !G()->close_flag();
|
if (!(td_->auth_manager_->is_authorized() && !G()->close_flag())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (G()->parameters().use_message_db || G()->parameters().use_chat_info_db || G()->parameters().use_file_db) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::get_memory_stats(bool full, Promise<MemoryStats> promise) const {
|
void MemoryManager::get_memory_stats(bool full, Promise<MemoryStats> promise) const {
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "td/telegram/InputMessageText.h"
|
#include "td/telegram/InputMessageText.h"
|
||||||
#include "td/telegram/Location.h"
|
#include "td/telegram/Location.h"
|
||||||
#include "td/telegram/logevent/LogEvent.h"
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/MessageContent.h"
|
#include "td/telegram/MessageContent.h"
|
||||||
#include "td/telegram/MessageEntity.h"
|
#include "td/telegram/MessageEntity.h"
|
||||||
#include "td/telegram/MessageEntity.hpp"
|
#include "td/telegram/MessageEntity.hpp"
|
||||||
@ -12441,9 +12442,11 @@ class MessagesManager::DialogFiltersLogEvent {
|
|||||||
|
|
||||||
void MessagesManager::tear_down() {
|
void MessagesManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesManager::start_up() {
|
void MessagesManager::start_up() {
|
||||||
init();
|
init();
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/logevent/LogEvent.h"
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
#include "td/telegram/logevent/LogEventHelper.h"
|
#include "td/telegram/logevent/LogEventHelper.h"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/MessagesManager.h"
|
#include "td/telegram/MessagesManager.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
#include "td/telegram/net/NetActor.h"
|
#include "td/telegram/net/NetActor.h"
|
||||||
@ -265,9 +266,11 @@ void PollManager::start_up() {
|
|||||||
|
|
||||||
void PollManager::tear_down() {
|
void PollManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (td_->memory_manager_->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PollManager::~PollManager() = default;
|
PollManager::~PollManager() = default;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "td/telegram/files/FileLoaderUtils.h"
|
#include "td/telegram/files/FileLoaderUtils.h"
|
||||||
#include "td/telegram/files/FileLocation.h"
|
#include "td/telegram/files/FileLocation.h"
|
||||||
#include "td/telegram/files/FileLocation.hpp"
|
#include "td/telegram/files/FileLocation.hpp"
|
||||||
|
#include "td/telegram/MemoryManager.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/logevent/LogEvent.h"
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
#include "td/telegram/misc.h"
|
#include "td/telegram/misc.h"
|
||||||
@ -4196,8 +4197,10 @@ void FileManager::memory_stats(vector<string> &output) {
|
|||||||
|
|
||||||
void FileManager::tear_down() {
|
void FileManager::tear_down() {
|
||||||
parent_.reset();
|
parent_.reset();
|
||||||
|
if (G()->memory_manager().get_actor_unsafe()->can_manage_memory()) {
|
||||||
// Completely clear memory when closing, to avoid memory leaks
|
// Completely clear memory when closing, to avoid memory leaks
|
||||||
memory_cleanup(true);
|
memory_cleanup(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
Reference in New Issue
Block a user