diff --git a/src/command_line.cc b/src/command_line.cc index 942c3d22..8e044cbf 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -2623,6 +2623,10 @@ void QueryDbMain(const std::string& bin_name, Config* config, MultiQueueWaiter* config, &db, waiter, &queue, &project, &file_consumer_shared, &import_manager, ×tamp_manager, &working_files, &clang_complete, &include_complete, global_code_complete_cache.get(), non_global_code_complete_cache.get(), signature_cache.get()); + + // Cleanup and free any unused memory. + FreeUnusedMemory(); + if (!did_work) { waiter->Wait({ IpcManager::instance()->threaded_queue_for_server_.get(), diff --git a/src/platform.h b/src/platform.h index 15a6b854..999fdf6e 100644 --- a/src/platform.h +++ b/src/platform.h @@ -50,4 +50,7 @@ void CopyFileTo(const std::string& destination, const std::string& source); bool IsSymLink(const std::string& path); // Returns any clang arguments that are specific to the current platform. -std::vector GetPlatformClangArguments(); \ No newline at end of file +std::vector GetPlatformClangArguments(); + +// Free any unused memory and return it to the system. +void FreeUnusedMemory(); diff --git a/src/platform_linux.cc b/src/platform_linux.cc index 240ed8c8..9ac4374b 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -247,4 +248,8 @@ std::vector GetPlatformClangArguments() { } #undef CHECKED +void FreeUnusedMemory() { + malloc_trim(0); +} + #endif diff --git a/src/platform_win.cc b/src/platform_win.cc index ac59f573..e3e4f991 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -226,4 +226,7 @@ std::vector GetPlatformClangArguments() { "-fdelayed-template-parsing" }; } + +void FreeUnusedMemory() {} + #endif