deallocate all managers
This commit is contained in:
parent
6e05d300dc
commit
4150a89cbb
@ -843,5 +843,9 @@ void AnimationsManager::get_current_state(vector<td_api::object_ptr<td_api::Upda
|
|||||||
updates.push_back(get_update_saved_animations_object());
|
updates.push_back(get_update_saved_animations_object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void AnimationsManager::memory_cleanup() {
|
||||||
|
animations_.clear();
|
||||||
|
animations_.rehash(0);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -31,6 +31,8 @@ class AnimationsManager : public Actor {
|
|||||||
public:
|
public:
|
||||||
AnimationsManager(Td *td, ActorShared<> parent);
|
AnimationsManager(Td *td, ActorShared<> parent);
|
||||||
|
|
||||||
|
void memory_cleanup();
|
||||||
|
|
||||||
int32 get_animation_duration(FileId file_id) const;
|
int32 get_animation_duration(FileId file_id) const;
|
||||||
|
|
||||||
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id, const char *source);
|
tl_object_ptr<td_api::animation> get_animation_object(FileId file_id, const char *source);
|
||||||
|
@ -274,5 +274,9 @@ tl_object_ptr<telegram_api::InputMedia> AudiosManager::get_input_media(
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
void AudiosManager::memory_cleanup() {
|
||||||
|
audios_.clear();
|
||||||
|
audios_.rehash(0);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -26,6 +26,8 @@ class AudiosManager {
|
|||||||
public:
|
public:
|
||||||
explicit AudiosManager(Td *td);
|
explicit AudiosManager(Td *td);
|
||||||
|
|
||||||
|
void memory_cleanup();
|
||||||
|
|
||||||
int32 get_audio_duration(FileId file_id) const;
|
int32 get_audio_duration(FileId file_id) const;
|
||||||
|
|
||||||
tl_object_ptr<td_api::audio> get_audio_object(FileId file_id);
|
tl_object_ptr<td_api::audio> get_audio_object(FileId file_id);
|
||||||
|
@ -5129,6 +5129,8 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) {
|
|||||||
documents_manager_->memory_cleanup();
|
documents_manager_->memory_cleanup();
|
||||||
video_notes_manager_->memory_cleanup();
|
video_notes_manager_->memory_cleanup();
|
||||||
videos_manager_->memory_cleanup();
|
videos_manager_->memory_cleanup();
|
||||||
|
audios_manager_->memory_cleanup();
|
||||||
|
animations_manager_->memory_cleanup();
|
||||||
file_manager_->memory_cleanup();
|
file_manager_->memory_cleanup();
|
||||||
|
|
||||||
malloc_trim(0);
|
malloc_trim(0);
|
||||||
|
@ -3733,167 +3733,169 @@ void FileManager::destroy_query(int32 file_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileManager::memory_cleanup() {
|
void FileManager::memory_cleanup() {
|
||||||
if (file_id_info_.size() > 1000 || empty_file_ids_.size() < 200) {
|
is_closed_ = true;
|
||||||
is_closed_ = true;
|
auto time = std::time(nullptr);
|
||||||
auto time = std::time(nullptr);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < file_id_info_.size(); i++) {
|
for (unsigned int i = 0; i < file_id_info_.size(); i++) {
|
||||||
auto main_node_id = file_id_info_[i].node_id_;
|
auto main_node_id = file_id_info_[i].node_id_;
|
||||||
if (main_node_id != 0) {
|
if (main_node_id != 0) {
|
||||||
auto &node = file_nodes_[main_node_id];
|
auto &node = file_nodes_[main_node_id];
|
||||||
if (node != nullptr && ((int32) i) == node->main_file_id_.fast_get()) {
|
|
||||||
if (time - node->main_file_id_.get_time() > 20 /* MAIN FILE TTL */) {
|
|
||||||
node->main_file_id_.reset_time();
|
|
||||||
|
|
||||||
for (auto &file_id : node->file_ids_) {
|
if (node != nullptr &&
|
||||||
/* DESTROY ASSOCIATED QUERIES */
|
node->download_priority_ == 0 &&
|
||||||
destroy_query(file_id.fast_get());
|
((int32) i) == node->main_file_id_.fast_get()) {
|
||||||
|
if (time - node->main_file_id_.get_time() > 20 /* MAIN FILE TTL */) {
|
||||||
|
node->main_file_id_.reset_time();
|
||||||
|
|
||||||
/* DESTROY ASSOCIATED NODE */
|
for (auto &file_id : node->file_ids_) {
|
||||||
auto &ref_node_id = file_id_info_[file_id.fast_get()].node_id_;
|
/* DESTROY ASSOCIATED QUERIES */
|
||||||
if (ref_node_id != 0 && ref_node_id != main_node_id) {
|
destroy_query(file_id.fast_get());
|
||||||
auto &ref_node = file_nodes_[ref_node_id];
|
|
||||||
if (ref_node != nullptr) {
|
/* DESTROY ASSOCIATED NODE */
|
||||||
context_->destroy_file_source(file_id);
|
auto &ref_node_id = file_id_info_[file_id.fast_get()].node_id_;
|
||||||
ref_node.reset();
|
if (ref_node_id != 0 && ref_node_id != main_node_id) {
|
||||||
}
|
auto &ref_node = file_nodes_[ref_node_id];
|
||||||
empty_node_ids_.push_back(ref_node_id);
|
if (ref_node != nullptr) {
|
||||||
file_nodes_[ref_node_id] = nullptr;
|
context_->destroy_file_source(file_id);
|
||||||
|
ref_node.reset();
|
||||||
}
|
}
|
||||||
|
empty_node_ids_.push_back(ref_node_id);
|
||||||
/* DESTROY ASSOCIATED FILE */
|
file_nodes_[ref_node_id] = nullptr;
|
||||||
empty_file_ids_.push_back(file_id.fast_get());
|
|
||||||
file_id_info_[file_id.fast_get()] = FileIdInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DESTROY MAIN QUERY */
|
/* DESTROY ASSOCIATED FILE */
|
||||||
destroy_query(i);
|
empty_file_ids_.push_back(file_id.fast_get());
|
||||||
|
file_id_info_[file_id.fast_get()] = FileIdInfo();
|
||||||
/* DESTROY FILE REFERENCE */
|
|
||||||
context_->destroy_file_source(node->main_file_id_);
|
|
||||||
|
|
||||||
/* DESTROY MAIN FILE */
|
|
||||||
empty_file_ids_.push_back(i);
|
|
||||||
file_id_info_[i] = FileIdInfo();
|
|
||||||
|
|
||||||
/* DESTROY MAIN NODE */
|
|
||||||
node.reset();
|
|
||||||
file_nodes_[main_node_id] = nullptr;
|
|
||||||
empty_node_ids_.push_back(main_node_id);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESTROY INVALID FILES */
|
/* DESTROY MAIN QUERY */
|
||||||
for (unsigned int i = 0; i < file_id_info_.size(); i++) {
|
|
||||||
auto &file = file_id_info_[i];
|
|
||||||
|
|
||||||
if (file.node_id_ != 0) {
|
|
||||||
auto &node = file_nodes_[file.node_id_];
|
|
||||||
|
|
||||||
if (node == nullptr) {
|
|
||||||
destroy_query(i);
|
destroy_query(i);
|
||||||
context_->destroy_file_source({(int32) i, 0});
|
|
||||||
|
/* DESTROY FILE REFERENCE */
|
||||||
|
context_->destroy_file_source(node->main_file_id_);
|
||||||
|
|
||||||
|
/* DESTROY MAIN FILE */
|
||||||
empty_file_ids_.push_back(i);
|
empty_file_ids_.push_back(i);
|
||||||
file_id_info_[i] = FileIdInfo();
|
file_id_info_[i] = FileIdInfo();
|
||||||
|
|
||||||
|
/* DESTROY MAIN NODE */
|
||||||
|
node.reset();
|
||||||
|
file_nodes_[main_node_id] = nullptr;
|
||||||
|
empty_node_ids_.push_back(main_node_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DESTROY INVALID NODES */
|
|
||||||
for (unsigned int i = 0; i < file_nodes_.size(); i++) {
|
|
||||||
auto &node = file_nodes_[i];
|
|
||||||
|
|
||||||
if (node != nullptr) {
|
|
||||||
auto invalid = file_id_info_[node->main_file_id_.fast_get()].node_id_ != ((int32) i);
|
|
||||||
|
|
||||||
if (!invalid) {
|
|
||||||
for (auto &file : node->file_ids_) {
|
|
||||||
if (file_id_info_[file.fast_get()].node_id_ != ((int32) i)) {
|
|
||||||
invalid = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (invalid) {
|
|
||||||
for (auto &file : node->file_ids_) {
|
|
||||||
destroy_query(file.fast_get());
|
|
||||||
context_->destroy_file_source(file);
|
|
||||||
empty_file_ids_.push_back(file.fast_get());
|
|
||||||
file_id_info_[file.fast_get()] = FileIdInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
empty_node_ids_.push_back(i);
|
|
||||||
file_nodes_[i] = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESTROY INVALID file_hash_to_file_id_ */
|
|
||||||
{
|
|
||||||
auto it = file_hash_to_file_id_.begin();
|
|
||||||
while (it != file_hash_to_file_id_.end()) {
|
|
||||||
auto &file = file_id_info_[it->second.fast_get()];
|
|
||||||
if (file_nodes_[file.node_id_] == nullptr) {
|
|
||||||
file_hash_to_file_id_.erase(it++);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESTROY INVALID local_location_to_file_id_ */
|
|
||||||
{
|
|
||||||
auto it = local_location_to_file_id_.begin();
|
|
||||||
while (it != local_location_to_file_id_.end()) {
|
|
||||||
auto &file = file_id_info_[it->second.fast_get()];
|
|
||||||
if (file_nodes_[file.node_id_] == nullptr) {
|
|
||||||
it = local_location_to_file_id_.erase(it++);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESTROY INVALID generate_location_to_file_id_ */
|
|
||||||
{
|
|
||||||
auto it = generate_location_to_file_id_.begin();
|
|
||||||
while (it != generate_location_to_file_id_.end()) {
|
|
||||||
auto &file = file_id_info_[it->second.fast_get()];
|
|
||||||
if (file_nodes_[file.node_id_] == nullptr) {
|
|
||||||
it = generate_location_to_file_id_.erase(it++);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DESTROY INVALID remote_location_info_ */
|
|
||||||
{
|
|
||||||
auto map = remote_location_info_.get_map();
|
|
||||||
auto it = map.begin();
|
|
||||||
while (it != map.end()) {
|
|
||||||
auto &file = file_id_info_[it->first.file_id_.fast_get()];
|
|
||||||
if (file_nodes_[file.node_id_] == nullptr) {
|
|
||||||
remote_location_info_.erase(it->second);
|
|
||||||
map.erase(it++);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file_hash_to_file_id_.rehash(0);
|
|
||||||
file_id_info_.shrink_to_fit();
|
|
||||||
empty_file_ids_.shrink_to_fit();
|
|
||||||
empty_node_ids_.shrink_to_fit();
|
|
||||||
|
|
||||||
LOG(ERROR) << empty_file_ids_.size() << " empty ids and " << queries_container_.size() << " running queries";
|
|
||||||
is_closed_ = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID FILES */
|
||||||
|
for (unsigned int i = 0; i < file_id_info_.size(); i++) {
|
||||||
|
auto &file = file_id_info_[i];
|
||||||
|
|
||||||
|
if (file.node_id_ != 0) {
|
||||||
|
auto &node = file_nodes_[file.node_id_];
|
||||||
|
|
||||||
|
if (node == nullptr) {
|
||||||
|
destroy_query(i);
|
||||||
|
context_->destroy_file_source({(int32) i, 0});
|
||||||
|
empty_file_ids_.push_back(i);
|
||||||
|
file_id_info_[i] = FileIdInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID NODES */
|
||||||
|
for (unsigned int i = 0; i < file_nodes_.size(); i++) {
|
||||||
|
auto &node = file_nodes_[i];
|
||||||
|
|
||||||
|
if (node != nullptr) {
|
||||||
|
auto invalid = file_id_info_[node->main_file_id_.fast_get()].node_id_ != ((int32) i);
|
||||||
|
|
||||||
|
if (!invalid) {
|
||||||
|
for (auto &file : node->file_ids_) {
|
||||||
|
if (file_id_info_[file.fast_get()].node_id_ != ((int32) i)) {
|
||||||
|
invalid = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (invalid) {
|
||||||
|
for (auto &file : node->file_ids_) {
|
||||||
|
destroy_query(file.fast_get());
|
||||||
|
context_->destroy_file_source(file);
|
||||||
|
empty_file_ids_.push_back(file.fast_get());
|
||||||
|
file_id_info_[file.fast_get()] = FileIdInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
empty_node_ids_.push_back(i);
|
||||||
|
file_nodes_[i] = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID file_hash_to_file_id_ */
|
||||||
|
{
|
||||||
|
auto it = file_hash_to_file_id_.begin();
|
||||||
|
while (it != file_hash_to_file_id_.end()) {
|
||||||
|
auto &file = file_id_info_[it->second.fast_get()];
|
||||||
|
if (file_nodes_[file.node_id_] == nullptr) {
|
||||||
|
file_hash_to_file_id_.erase(it++);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID local_location_to_file_id_ */
|
||||||
|
{
|
||||||
|
auto it = local_location_to_file_id_.begin();
|
||||||
|
while (it != local_location_to_file_id_.end()) {
|
||||||
|
auto &file = file_id_info_[it->second.fast_get()];
|
||||||
|
if (file_nodes_[file.node_id_] == nullptr) {
|
||||||
|
it = local_location_to_file_id_.erase(it++);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID generate_location_to_file_id_ */
|
||||||
|
{
|
||||||
|
auto it = generate_location_to_file_id_.begin();
|
||||||
|
while (it != generate_location_to_file_id_.end()) {
|
||||||
|
auto &file = file_id_info_[it->second.fast_get()];
|
||||||
|
if (file_nodes_[file.node_id_] == nullptr) {
|
||||||
|
it = generate_location_to_file_id_.erase(it++);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DESTROY INVALID remote_location_info_ */
|
||||||
|
{
|
||||||
|
auto map = remote_location_info_.get_map();
|
||||||
|
auto it = map.begin();
|
||||||
|
while (it != map.end()) {
|
||||||
|
auto &file = file_id_info_[it->first.file_id_.fast_get()];
|
||||||
|
if (file_nodes_[file.node_id_] == nullptr) {
|
||||||
|
remote_location_info_.erase(it->second);
|
||||||
|
map.erase(it++);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file_hash_to_file_id_.rehash(0);
|
||||||
|
file_id_info_.shrink_to_fit();
|
||||||
|
empty_file_ids_.shrink_to_fit();
|
||||||
|
empty_node_ids_.shrink_to_fit();
|
||||||
|
|
||||||
|
LOG(ERROR) << empty_file_ids_.size() << " empty ids and " << queries_container_.size() << " running queries";
|
||||||
|
is_closed_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::tear_down() {
|
void FileManager::tear_down() {
|
||||||
|
Reference in New Issue
Block a user