Permalink
Browse files

Use malloc_trim when using glibc

* use malloc_trim(0) to return memory to OS after free (after closing window)
* release the memory when clearing history and call malloc_trim()
  • Loading branch information...
42wim committed Jan 17, 2015
1 parent df6488a commit 429fc7a7498ca39c5210b26d4e541e8d6969db3a
Showing with 23 additions and 1 deletion.
  1. +16 −1 cmd-clear-history.c
  2. +7 −0 grid.c
View
@@ -17,6 +17,9 @@
*/
#include <sys/types.h>
#ifdef __GLIBC__
# include <malloc.h>
#endif
#include "tmux.h"
@@ -40,12 +43,24 @@ cmd_clear_history_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct window_pane *wp;
struct grid *gd;
struct grid_line *gl;
u_int yy;
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
gd = wp->base.grid;
grid_move_lines(gd, 0, gd->hsize, gd->sy);
for (yy = 0; yy < gd->hsize+gd->sy; yy++) {
gl = &gd->linedata[yy];
free(gl->celldata);
}
free(gd->linedata);
# ifdef M_TRIM_THRESHOLD
malloc_trim(0);
# endif
gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
gd->hsize = 0;
return (CMD_RETURN_NORMAL);
View
7 grid.c
@@ -20,6 +20,9 @@
#include <stdlib.h>
#include <string.h>
#ifdef __GLIBC__
# include <malloc.h>
#endif
#include "tmux.h"
@@ -113,6 +116,10 @@ grid_destroy(struct grid *gd)
free(gd->linedata);
free(gd);
# ifdef M_TRIM_THRESHOLD
malloc_trim(0);
# endif
}
/* Compare grids. */

0 comments on commit 429fc7a

Please sign in to comment.