unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Memory leak in keyboard variables?
@ 2008-12-11  3:03 Chong Yidong
  2008-12-11  9:30 ` Andreas Schwab
  2008-12-11 15:59 ` Stefan Monnier
  0 siblings, 2 replies; 20+ messages in thread
From: Chong Yidong @ 2008-12-11  3:03 UTC (permalink / raw)
  To: emacs-devel

I've been looking into the memory leak that occurs when terminal frames
are killed.  From Markus Triska's recipe:

 emacs -nw -f server-start
 for i in {1..100}; do emacsclient -t -e "(save-buffers-kill-terminal)"; done 

I think at least some of this leakage is due to unfreed Lisp objects.
For instance, this code in xterm.el leads to ~ 1000 unfreed conses per
terminal created and destroyed:

   (let ((map (copy-keymap xterm-function-map)))
      ...
      (set-keymap-parent map (keymap-parent input-decode-map))
      (set-keymap-parent input-decode-map map)))

Now, input-decode-map is defined in keyboard.c, using DEFVAR_KBOARD.  It
is a Lisp_Misc_Kboard_Objfwd object, and if I'm not mistaken, such
objects are not garbage-collected.

When the terminal is killed, are its keyboard's Lisp_Misc_Kboard_Objfwd
objects freed?  As far as I can tell, they are not freed.  But I am no
expert in this part of the code, so maybe someone else can clue me in.




^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Memory leak in keyboard variables?
@ 2008-12-15  1:26 Kenichi Handa
  2008-12-15  3:16 ` Chong Yidong
  0 siblings, 1 reply; 20+ messages in thread
From: Kenichi Handa @ 2008-12-15  1:26 UTC (permalink / raw)
  To: emacs-devel

> One thing I noticed is the xftfont_open is run whenever we
> call "emacsclient -c", but xftfont_close is never called.
> It appears that font_open_entity is called to allocate a
> font object, it is in general not recorded anywhere.

No.  A font object is recorded in FONT_OBJLIST_INDEX of a
font-entity.

> Could this be part of the problem?

The strategy is to record all font-objects in font-entities, and
record all font-entities in a cache of each font-backend.  The caches
are freed when `delete-frame' calls font_update_drivers with
new_drivers as nil through this calling sequence.

font_update_drivers -> font_finish_cache -> font_clear_cache

At that time all font-entities and font-obects are freed.

If there's a memory leak for font objectes, it means that there is a
bug at some code implementing the above strategy.

I don't have a time to tackle this problem at the moment,
but I'll take care of it as soon as possible.

---
Kenichi Handa
handa@m17n.org




^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Memory leak in keyboard variables?
@ 2008-12-16  2:14 Chetan Pandya
  2008-12-16  3:33 ` Chong Yidong
  0 siblings, 1 reply; 20+ messages in thread
From: Chetan Pandya @ 2008-12-16  2:14 UTC (permalink / raw)
  To: Chong Yidong, Kenichi Handa; +Cc: emacs-devel

Although not related, spotted while looking at the code in font.c: font_update_drivers
       for (list = f->font_driver_list; list; list = list->next)
 	if (! list->on)
-	  list_table[i] = list;
+	  list_table[i++] = list;
       list_table[i] = NULL;
 
Chetan


--- On Mon, 12/15/08, Chong Yidong <cyd@stupidchicken.com> wrote:

> From: Chong Yidong <cyd@stupidchicken.com>
> > The strategy is to record all font-objects in
> font-entities, and
> > record all font-entities in a cache of each
> font-backend.  The caches
> > are freed when `delete-frame' calls
> font_update_drivers with
> > new_drivers as nil
> 
> Thanks for the explanation.  It was very helpful.
> 
> I think the problem is that font_clear_cache is incorrectly
> written.
> For some reason, it assumes that the font cache entries
> have the form
> 
>   (font-spec [entity1 entity2...])
> 
> when in fact, they have the form
> 
>   (font-spec entity1 entity2...)
> 
> The following patch to font_clear_cache frees 60-70k of
> memory per
> terminal.
> 
> Do you know why font_clear_cache was written this way, and
> whether there
> could be any other places in the font code that make this
> incorrect
> assumption?
> 
> *** trunk/src/font.c.~1.99.~	2008-12-13 10:39:30.000000000
> -0500
> --- trunk/src/font.c	2008-12-14 22:06:26.000000000 -0500
> ***************
> *** 2651,2671 ****
>        struct font_driver *driver;
>   {
>     Lisp_Object tail, elt;
>   
>     /* CACHE = (DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...)
> */
>     for (tail = XCDR (XCDR (cache)); CONSP (tail); tail =
> XCDR (tail))
>       {
>         elt = XCAR (tail);
> !       if (CONSP (elt) && FONT_SPEC_P (XCAR (elt))
> && VECTORP (XCDR (elt)))
>   	{
> ! 	  Lisp_Object vec = XCDR (elt);
> ! 	  int i;
> ! 
> ! 	  for (i = 0; i < ASIZE (vec); i++)
>   	    {
> ! 	      Lisp_Object entity = AREF (vec, i);
>   
> ! 	      if (EQ (driver->type, AREF (entity,
> FONT_TYPE_INDEX)))
>   		{
>   		  Lisp_Object objlist = AREF (entity,
> FONT_OBJLIST_INDEX);
>   
> --- 2651,2671 ----
>        struct font_driver *driver;
>   {
>     Lisp_Object tail, elt;
> +   Lisp_Object tail2, entity;
>   
>     /* CACHE = (DRIVER-TYPE NUM-FRAMES FONT-CACHE-DATA ...)
> */
>     for (tail = XCDR (XCDR (cache)); CONSP (tail); tail =
> XCDR (tail))
>       {
>         elt = XCAR (tail);
> !       /* elt should have the form (FONT-SPEC FONT-ENTITY
> ...) */
> !       if (CONSP (elt) && FONT_SPEC_P (XCAR
> (elt)))
>   	{
> ! 	  for (tail2 = XCDR (elt); CONSP (tail2); tail2 = XCDR
> (tail2))
>   	    {
> ! 	      entity = XCAR (tail2);
>   
> ! 	      if (FONT_ENTITY_P (entity)
> ! 		  && EQ (driver->type, AREF (entity,
> FONT_TYPE_INDEX)))
>   		{
>   		  Lisp_Object objlist = AREF (entity,
> FONT_OBJLIST_INDEX);






^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2008-12-20 20:41 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-11  3:03 Memory leak in keyboard variables? Chong Yidong
2008-12-11  9:30 ` Andreas Schwab
2008-12-11 15:09   ` Chong Yidong
2008-12-11 20:43     ` Chong Yidong
2008-12-13 14:19       ` Markus Triska
2008-12-13 19:09         ` Chong Yidong
2008-12-16 14:11         ` Chong Yidong
2008-12-17  4:40           ` Stephen J. Turnbull
2008-12-20  1:50             ` Chong Yidong
2008-12-20 15:34               ` Jan Djärv
2008-12-20 17:09                 ` Markus Triska
2008-12-20 17:45                 ` Dan Nicolaescu
2008-12-20 18:37                   ` Dan Nicolaescu
2008-12-20 20:41                 ` Chong Yidong
2008-12-11 15:59 ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2008-12-15  1:26 Kenichi Handa
2008-12-15  3:16 ` Chong Yidong
2008-12-16  4:31   ` Kenichi Handa
2008-12-16  2:14 Chetan Pandya
2008-12-16  3:33 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).