pastebin - collaborative debugging tool
tmux.kpaste.net RSS


improvement
Posted by Anonymous on Wed 14th Jan 2015 00:31
raw | new post
view followups (newest first): improvement? by Anonymous

  1. 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).
  2. 20150113.21:13:44        wim | 128Mb at the moment for 8 windows
  3. 20150113.21:14:31        wim | memory leak?
  4.  
  5. 20150114.00:47:03       nicm | tmux returns memory to libc and is reliant on it to return it to the kernel
  6. 20150114.00:47:14       nicm | glibc does not do so very aggressively
  7. 20150114.00:47:19       nicm | this is a common issue on linux
  8. 20150114.00:47:48       nicm | there is a library call you can put into tmux if you want it to be returned more quickly
  9. 20150114.00:48:32       nicm | malloc_trim(3)
  10. 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
  11. 20150114.00:50:24       nicm | or just live with it and assume glibc knows best
  12. 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
  13.  
  14. 20150114.01:05:47        wim | nicm: nice! malloc_trim(0) works
  15.  
  16. 20150114.01:11:55  freeroute | wim: are you running Linux? How did you get it working? Just add to source code?
  17. 20150114.01:12:12        wim | freeroute: yes and yes
  18. 20150114.01:12:35        wim | in grid_destroy()
  19. 20150114.01:12:35        wim |     free(gd);
  20. 20150114.01:12:35        wim |     malloc_trim(0);
  21. 20150114.01:12:45        wim | add it under the last free
  22. 20150114.01:14:41        wim | would be nice if it got into the code though :/
  23.  
  24.  
  25. ================================================================================================================================
  26.  
  27. So basically, in tmux/grid.c - you want it to look like this:
  28.  
  29. /* Destroy grid. */
  30. void
  31. grid_destroy(struct grid *gd)
  32. {
  33.         struct grid_line        *gl;
  34.         u_int                    yy;
  35.  
  36.         for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
  37.                 gl = &gd->linedata[yy];
  38.                 free(gl->celldata);
  39.         }
  40.  
  41.         free(gd->linedata);
  42.  
  43.         free(gd);
  44.         malloc_trim(0);
  45. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at