Free memory
This commit is contained in:
parent
4e021b397a
commit
b1e9774e62
@ -13611,27 +13611,50 @@ void ContactsManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
|
||||
void ContactsManager::memory_cleanup() {
|
||||
users_full_.clear();
|
||||
users_full_.rehash(0);
|
||||
bot_infos_.clear();
|
||||
bot_infos_.rehash(0);
|
||||
user_photos_.clear();
|
||||
user_photos_.rehash(0);
|
||||
user_profile_photo_file_source_ids_.clear();
|
||||
user_profile_photo_file_source_ids_.rehash(0);
|
||||
chat_photo_file_source_ids_.clear();
|
||||
chat_photo_file_source_ids_.rehash(0);
|
||||
channels_full_.clear();
|
||||
channels_full_.rehash(0);
|
||||
channel_photo_file_source_ids_.clear();
|
||||
channel_photo_file_source_ids_.rehash(0);
|
||||
secret_chats_.clear();
|
||||
secret_chats_.rehash(0);
|
||||
secret_chats_with_user_.clear();
|
||||
secret_chats_with_user_.rehash(0);
|
||||
chat_invite_links_.clear();
|
||||
chat_invite_links_.rehash(0);
|
||||
channel_invite_links_.clear();
|
||||
channel_invite_links_.rehash(0);
|
||||
invite_link_infos_.clear();
|
||||
invite_link_infos_.rehash(0);
|
||||
load_user_from_database_queries_.clear();
|
||||
load_user_from_database_queries_.rehash(0);
|
||||
load_chat_from_database_queries_.clear();
|
||||
load_chat_from_database_queries_.rehash(0);
|
||||
load_channel_from_database_queries_.clear();
|
||||
load_channel_from_database_queries_.rehash(0);
|
||||
load_secret_chat_from_database_queries_.clear();
|
||||
load_secret_chat_from_database_queries_.rehash(0);
|
||||
dialog_administrators_.clear();
|
||||
dialog_administrators_.rehash(0);
|
||||
uploaded_profile_photos_.clear();
|
||||
uploaded_profile_photos_.rehash(0);
|
||||
imported_contacts_.clear();
|
||||
imported_contacts_.rehash(0);
|
||||
received_channel_participant_.clear();
|
||||
received_channel_participant_.rehash(0);
|
||||
received_channel_participants_.clear();
|
||||
received_channel_participants_.rehash(0);
|
||||
cached_channel_participants_.clear();
|
||||
cached_channel_participants_.rehash(0);
|
||||
linked_channel_ids_.clear();
|
||||
linked_channel_ids_.rehash(0);
|
||||
}
|
||||
} // namespace td
|
||||
|
@ -667,6 +667,7 @@ bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_de
|
||||
|
||||
void DocumentsManager::memory_cleanup() {
|
||||
documents_.clear();
|
||||
documents_.rehash(0);
|
||||
}
|
||||
|
||||
string DocumentsManager::get_document_search_text(FileId file_id) const {
|
||||
|
@ -6209,18 +6209,31 @@ void StickersManager::get_current_state(vector<td_api::object_ptr<td_api::Update
|
||||
|
||||
void StickersManager::memory_cleanup() {
|
||||
stickers_.clear();
|
||||
stickers_.rehash(0);
|
||||
sticker_sets_.clear();
|
||||
sticker_sets_.rehash(0);
|
||||
short_name_to_sticker_set_id_.clear();
|
||||
short_name_to_sticker_set_id_.rehash(0);
|
||||
attached_sticker_sets_.clear();
|
||||
attached_sticker_sets_.rehash(0);
|
||||
found_stickers_.clear();
|
||||
found_stickers_.rehash(0);
|
||||
found_sticker_sets_.clear();
|
||||
found_sticker_sets_.rehash(0);
|
||||
special_sticker_sets_.clear();
|
||||
special_sticker_sets_.rehash(0);
|
||||
sticker_set_load_requests_.clear();
|
||||
sticker_set_load_requests_.rehash(0);
|
||||
emoji_language_codes_.clear();
|
||||
emoji_language_codes_.rehash(0);
|
||||
emoji_language_code_versions_.clear();
|
||||
emoji_language_code_versions_.rehash(0);
|
||||
emoji_language_code_last_difference_times_.clear();
|
||||
emoji_language_code_last_difference_times_.rehash(0);
|
||||
emoji_suggestions_urls_.clear();
|
||||
emoji_suggestions_urls_.rehash(0);
|
||||
dice_messages_.clear();
|
||||
dice_messages_.rehash(0);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -5127,6 +5127,8 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) {
|
||||
videos_manager_->memory_cleanup();
|
||||
file_manager_->memory_cleanup();
|
||||
|
||||
malloc_trim(0);
|
||||
|
||||
std::vector<FileType> file_types;
|
||||
for (auto &file_type : request.file_types_) {
|
||||
if (file_type == nullptr) {
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
@ -248,6 +248,7 @@ tl_object_ptr<telegram_api::InputMedia> VideoNotesManager::get_input_media(
|
||||
|
||||
void VideoNotesManager::memory_cleanup() {
|
||||
video_notes_.clear();
|
||||
video_notes_.rehash(0);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -302,6 +302,7 @@ string VideosManager::get_video_search_text(FileId file_id) const {
|
||||
}
|
||||
void VideosManager::memory_cleanup() {
|
||||
videos_.clear();
|
||||
videos_.rehash(0);
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -1598,10 +1598,15 @@ vector<FileId> WebPagesManager::get_web_page_file_ids(const WebPage *web_page) c
|
||||
}
|
||||
|
||||
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();
|
||||
web_pages_.clear();
|
||||
web_pages_.rehash(0);
|
||||
web_page_messages_.clear();
|
||||
web_page_messages_.rehash(0);
|
||||
got_web_page_previews_.clear();
|
||||
got_web_page_previews_.rehash(0);
|
||||
url_to_web_page_id_.clear();
|
||||
url_to_web_page_id_.rehash(0);
|
||||
url_to_file_source_id_.clear();
|
||||
url_to_file_source_id_.rehash(0);
|
||||
}
|
||||
} // namespace td
|
||||
|
@ -3456,7 +3456,7 @@ void FileManager::hangup() {
|
||||
}
|
||||
|
||||
void FileManager::memory_cleanup() {
|
||||
if (file_id_info_.size() > 1000 && empty_file_ids_.size() < 200) {
|
||||
if (file_id_info_.size() > 1000 || empty_file_ids_.size() < 200) {
|
||||
is_closed_ = true;
|
||||
auto time = std::time(nullptr);
|
||||
|
||||
@ -3477,7 +3477,7 @@ void FileManager::memory_cleanup() {
|
||||
|
||||
/* DESTROY ASSOCIATED FILE */
|
||||
empty_file_ids_.push_back(file_id.get());
|
||||
file_id_info_[file_id.get()] = FileIdInfo();
|
||||
file_id_info_.erase(file_id_info_.begin() + ((int32) file_id.get()));
|
||||
}
|
||||
|
||||
/* DESTROY MAIN QUERY */
|
||||
@ -3489,9 +3489,9 @@ void FileManager::memory_cleanup() {
|
||||
}
|
||||
|
||||
/* DESTROY MAIN FILE */
|
||||
file_id_insert_time_[i] = INT64_MAX;
|
||||
file_id_insert_time_.erase(((int32) i));
|
||||
empty_file_ids_.push_back(i);
|
||||
file_id_info_[i] = FileIdInfo();
|
||||
file_id_info_.erase(file_id_info_.begin() + ((int32) i));
|
||||
|
||||
/* DESTROY MAIN NODE */
|
||||
file_nodes_[main_node_id] = nullptr;
|
||||
@ -3500,6 +3500,9 @@ void FileManager::memory_cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
vector<FileIdInfo>(file_id_info_).swap(file_id_info_);
|
||||
vector<int32>(empty_file_ids_).swap(empty_file_ids_);
|
||||
|
||||
LOG(INFO) << empty_file_ids_.size() << " empty ids and " << queries_container_.size() << " running queries";
|
||||
is_closed_ = false;
|
||||
}
|
||||
@ -3508,4 +3511,4 @@ void FileManager::memory_cleanup() {
|
||||
void FileManager::tear_down() {
|
||||
parent_.reset();
|
||||
}
|
||||
} // namespace tds
|
||||
} // namespace td
|
||||
|
@ -557,7 +557,7 @@ class FileManager : public FileLoadManager::Callback {
|
||||
std::map<FileDbId, int32> pmc_id_to_file_node_id_;
|
||||
std::unordered_map<int32, int64> file_id_insert_time_;
|
||||
|
||||
vector<FileIdInfo> file_id_info_;
|
||||
std::vector<FileIdInfo> file_id_info_;
|
||||
vector<int32> empty_file_ids_;
|
||||
vector<unique_ptr<FileNode>> file_nodes_;
|
||||
ActorOwn<FileLoadManager> file_load_manager_;
|
||||
|
Reference in New Issue
Block a user