summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build9
-rw-r--r--plugins/datetime/gsd-datetime.service.in2
-rw-r--r--plugins/datetime/weather-tz.c12
3 files changed, 23 insertions, 0 deletions
diff --git a/meson.build b/meson.build
index cd8616cb..578ae07a 100644
--- a/meson.build
+++ b/meson.build
@@ -219,6 +219,15 @@ if enable_network_manager
endif
config_h.set10('HAVE_NETWORK_MANAGER', enable_network_manager)
+# check for malloc_trim(0)
+malloc_trim_code = '''
+#include <malloc.h>
+void func() { malloc_trim(0); }
+'''
+if cc.compiles(malloc_trim_code, name: 'malloc_trim')
+ config_h.set10('HAVE_MALLOC_TRIM', 1)
+endif
+
gnome = import('gnome')
i18n = import('i18n')
pkg = import('pkgconfig')
diff --git a/plugins/datetime/gsd-datetime.service.in b/plugins/datetime/gsd-datetime.service.in
index bd4692b8..0607087f 100644
--- a/plugins/datetime/gsd-datetime.service.in
+++ b/plugins/datetime/gsd-datetime.service.in
@@ -17,3 +17,5 @@ ExecStart=@libexecdir@/gsd-datetime
Restart=on-failure
BusName=@plugin_dbus_name@
TimeoutStopSec=5
+# gsd-datetime will use malloc_trim()
+Environment=G_SLICE=always-malloc
diff --git a/plugins/datetime/weather-tz.c b/plugins/datetime/weather-tz.c
index f4afdaca..47fa6d31 100644
--- a/plugins/datetime/weather-tz.c
+++ b/plugins/datetime/weather-tz.c
@@ -24,6 +24,9 @@
#endif
#include <dlfcn.h>
+#ifdef HAVE_MALLOC_TRIM
+# include <malloc.h>
+#endif
#include "weather-tz.h"
#include "tz.h"
@@ -112,6 +115,15 @@ release_world (void)
if (release_world_func != NULL) {
g_debug ("Releasing Locations.xml data");
release_world_func ();
+
+#ifdef HAVE_MALLOC_TRIM
+ /* A lot of the memory we just allocated won't be released back
+ * to the operating system unless malloc is told to release it.
+ * This also pretty much relies on G_SLICE=always-malloc so
+ * that libgweather does not allocate everything with gslice.
+ */
+ malloc_trim (0);
+#endif
}
else {
g_debug ("Cannot locate symbol _gweather_location_reset_world()");