diff --git a/configure.ac b/configure.ac index 81a256a2c2a354b0fa610379b1be06e90c4bcc27..7e37622422b0cce055d91542d1d7d45cf7548f69 100644 --- a/configure.ac +++ b/configure.ac @@ -123,7 +123,7 @@ AC_SYS_LARGEFILE() dnl ********************************** dnl *** Check for standard headers *** dnl ********************************** -AC_CHECK_HEADERS([ctype.h errno.h fcntl.h grp.h limits.h locale.h memory.h \ +AC_CHECK_HEADERS([ctype.h errno.h fcntl.h grp.h limits.h locale.h malloc.h memory.h \ paths.h pwd.h sched.h signal.h stdarg.h stdlib.h string.h \ sys/mman.h sys/param.h sys/stat.h sys/time.h sys/types.h \ sys/uio.h sys/wait.h time.h]) diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c index 33bf569212809e0b4ba2ced2e502d2852ee7b5da..61d7bd59208abd0fad0f6fe21cf1a10eebd80a68 100644 --- a/thunar/thunar-application.c +++ b/thunar/thunar-application.c @@ -27,6 +27,9 @@ #ifdef HAVE_ERRNO_H #include <errno.h> #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif #ifdef HAVE_MEMORY_H #include <memory.h> #endif @@ -2908,3 +2911,28 @@ thunar_application_get_thumbnail_cache (ThunarApplication *application) return g_object_ref (application->thumbnail_cache); } + + + +static gboolean +thunar_application_malloc_trim_idle (gpointer application_ptr) +{ +#ifdef __GLIBC__ + /* Workaround to make the kernel reclaim memory which is not used by Thunar anymore. */ + /* When using glibc, after releasing bigger memory chunks it seems to be required to call that 'garbage collector'. */ + /* More information here: https://gitlab.xfce.org/xfce/thunar/-/issues/1552#note_101990 */ + malloc_trim (0); +#endif + + return FALSE; +} + + + +void +thunar_application_malloc_trim_on_idle (ThunarApplication *application) +{ + _thunar_return_if_fail (THUNAR_IS_APPLICATION (application)); + + g_idle_add (thunar_application_malloc_trim_idle, application); +} diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h index 4b1f281e8c806b358e5f6e62e465b03bcb563d86..8c7ba6dce1d0465f27691754f92f9d0da238edc7 100644 --- a/thunar/thunar-application.h +++ b/thunar/thunar-application.h @@ -205,6 +205,9 @@ thunar_application_get_thumbnail_cache (ThunarApplication *application); gboolean thunar_application_accel_map_init (ThunarApplication *application); +void +thunar_application_malloc_trim_on_idle (ThunarApplication *application); + G_END_DECLS; #endif /* !__THUNAR_APPLICATION_H__ */ diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 9227b8bfb753459764184cc3a86bc0dae1db8f87..3afd85f17bf8d48768812b0293f92cc463b6a834 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -3670,6 +3670,8 @@ thunar_window_reset_view_type_idle_destroyed (gpointer data) gboolean thunar_window_action_cancel_search (ThunarWindow *window) { + ThunarApplication *application; + _thunar_return_val_if_fail (THUNAR_IS_LOCATION_BAR (window->location_bar), FALSE); _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE); @@ -3708,6 +3710,11 @@ thunar_window_action_cancel_search (ThunarWindow *window) /* bring back the original location bar style (relevant if the bar is hidden) */ thunar_window_update_location_bar_visible (window); + /* tidy up memory after a search */ + application = thunar_application_get (); + thunar_application_malloc_trim_on_idle (application); + g_object_unref (application); + /* required in case of shortcut activation, in order to signal that the accel key got handled */ return TRUE; }