20150113.21:13:21 wim | hi guys, after using tmux for a while it seems like it's using quite some memory (using 1.9a). 20150113.21:13:44 wim | 128Mb at the moment for 8 windows 20150113.21:14:31 wim | memory leak? 20150114.00:47:03 nicm | tmux returns memory to libc and is reliant on it to return it to the kernel 20150114.00:47:14 nicm | glibc does not do so very aggressively 20150114.00:47:19 nicm | this is a common issue on linux 20150114.00:47:48 nicm | there is a library call you can put into tmux if you want it to be returned more quickly 20150114.00:48:32 nicm | malloc_trim(3) 20150114.00:50:08 nicm | add malloc_trim(0) somewhere, server_second_callback in server.c would be a good place, or grid_destroy in grid.c 20150114.00:50:24 nicm | or just live with it and assume glibc knows best 20150114.00:51:23 nicm | i believe OS X is similar, if not worse, although it has different ways to reclaim the memory, i think it is kernel-side there 20150114.01:05:47 wim | nicm: nice! malloc_trim(0) works 20150114.01:11:55 freeroute | wim: are you running Linux? How did you get it working? Just add to source code? 20150114.01:12:12 wim | freeroute: yes and yes 20150114.01:12:35 wim | in grid_destroy() 20150114.01:12:35 wim | free(gd); 20150114.01:12:35 wim | malloc_trim(0); 20150114.01:12:45 wim | add it under the last free 20150114.01:14:41 wim | would be nice if it got into the code though :/ ================================================================================================================================ So basically, in tmux/grid.c - you want it to look like this: /* Destroy grid. */ void grid_destroy(struct grid *gd) { struct grid_line *gl; u_int yy; for (yy = 0; yy < gd->hsize + gd->sy; yy++) { gl = &gd->linedata[yy]; free(gl->celldata); } free(gd->linedata); free(gd); malloc_trim(0); } ================================================================================================================================ :( 20150117.22:21:01 wim | nicm: is this something that could be merged? makes it portable? the malloc_trim thing - | https://github.com/42wim/tmux/commit/429fc7a7498ca39c5210b26d4e541e8d6969db3a 20150117.22:24:42 freeroute | wim: does the code say like "If this is going to get compiled by glibc, then also include this code" and by 'this code' I mean that malloc_trim thing. 20150117.22:26:10 freeroute | if so then that means I can read C :D 20150117.22:26:59 wim | that's the gist of it yes 20150117.22:45:40 nicm | not really 20150117.22:46:45 nicm | it's up to glibc how malloc works really 20150117.22:52:26 wim | nicm: no power to the people instead of letting the system decide ? :-) 20150117.22:53:46 wim | nicm: i tried fiddling with the environment variables, but didn't get it to work as well as malloc_trim() 20150117.22:55:48 nicm | you need to talk to the glibc folks if their environment vars don't work 20150117.22:57:26 nicm | i don't think we should do this in the code 20150117.22:58:47 wim | ok thanks, was worth a try