[gegl] buffer: when building against glibc, issue malloc_trim after finalizing GeglBuffers



commit d71097d4af59c71e738c72a4f7abd5dcff27d8d7
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Apr 15 04:19:33 2019 +0200

    buffer: when building against glibc, issue malloc_trim after finalizing GeglBuffers
    
    This will sometimes permit returning memory to the operating system when
    just malloc/free calls alone do not do so. GeglBuffers are likely the largest
    composite objects in a process with GEGL - thus here, or even periodically
    in some other way is a way to force glibc's malloc/free to give up pages.

 gegl/buffer/gegl-buffer.c | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index c233503ba..4d1dd4854 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -53,6 +53,10 @@
 #include <execinfo.h>
 #endif
 
+#ifdef __GLIBC__
+#include <malloc.h>
+#endif
+
 
 G_DEFINE_TYPE (GeglBuffer, gegl_buffer, GEGL_TYPE_TILE_HANDLER)
 
@@ -408,6 +412,11 @@ gegl_buffer_finalize (GObject *object)
   g_free (GEGL_BUFFER (object)->path);
   g_atomic_int_inc (&de_allocated_buffers);
   G_OBJECT_CLASS (parent_class)->finalize (object);
+
+
+#ifdef __GLIBC__
+  malloc_trim (1024 * 1024);
+#endif
 }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]