2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Limit the amount of malloc arenas and call malloc_trim periodically with glibc

To prevent excessive memory usage looking like memory leak
This commit is contained in:
Ilya Fedin
2025-06-25 22:06:05 +00:00
committed by John Preston
parent ef69796798
commit 77642d2876

View File

@@ -22,6 +22,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <gio/gio.hpp>
#include <xdpinhibit/xdpinhibit.hpp>
#ifdef __GLIBC__
#include <malloc.h>
#endif // __GLIBC__
namespace Platform {
namespace {
@@ -166,6 +170,14 @@ LinuxIntegration::LinuxIntegration()
g_warning("Qt is running without GLib event loop integration, "
"expect various functionality to not to work.");
}
#ifdef __GLIBC__
mallopt(M_ARENA_MAX, 1);
QObject::connect(
QCoreApplication::eventDispatcher(),
&QAbstractEventDispatcher::aboutToBlock,
[] { malloc_trim(0); });
#endif // __GLIBC__
}
void LinuxIntegration::init() {