aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cmdline.cpp
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2015-02-24 00:06:54 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2015-03-02 00:03:51 +0100
commita399be7f24d58080282316d1ec529bf5aed67634 (patch)
treeb67c1fb82969a60d359875e0fd0e51b4d9ff1c98 /src/cmdline.cpp
parentef82d22045f7e08eb6ebcd84893d23286be72ba5 (diff)
downloadsciteco-a399be7f24d58080282316d1ec529bf5aed67634.tar.gz
try hard to free heap memory after command-line termination using malloc_trim()
* this is a Linux/glibc-only optimization
Diffstat (limited to 'src/cmdline.cpp')
-rw-r--r--src/cmdline.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index 83a90b4..599a469 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -19,6 +19,10 @@
#include "config.h"
#endif
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
#include <string.h>
#include <signal.h>
@@ -446,10 +450,17 @@ Cmdline::process_edit_cmd(gchar key)
str = NULL;
len = rubout_len = 0;
+#ifdef HAVE_MALLOC_TRIM
/*
- * FIXME: Perhaps to the malloc_trim() here
- * instead of in UndoStack::clear()
+ * Glibc/Linux-only optimization: Undo stacks can grow very
+ * large - sometimes large enough to make the system
+ * swap and become unresponsive.
+ * This will often reduce the amount of memory previously
+ * freed that's still allocated to the program immediately
+ * when the command-line is terminated:
*/
+ malloc_trim(0);
+#endif
} else {
insert(key);
}