Subject: Re: bug#21556: 25.0.50; Memory leak in emacs -Q with lucid (font)

From: Eli Zaretskii <[email-masked]>
Date: Fri, 25 Sep 2015 09:45:44 +0300

> From: Dima Kogan <[email-masked]>
> Date: Thu, 24 Sep 2015 17:05:12 -0700
> 
> Main question of this bug report so far:
> 
>   Is there a way to put a watchpoint on a lisp object?

Theoretically, yes.

> How?

Depends on the object.  Which object do you want to put the watchpoint
on?  Please show its source variable name and the source file lines
where it is used.  Also, if the object is complex, what kinds of
changes in it would you like to watch?

> I'm observing that most (but not all) of the time, the menu font is
> being created around the same time as the cache reset. Backtrace:
> 
> 	    7fcf06d1e99f XftFontOpenName (/usr/lib/x86_64-linux-gnu/libXft.so.2.3.2)
> 	          6b5861 openXftFont (/tmp/emacs-tst)
> 	          6b5999 XlwMenuInitialize (/tmp/emacs-tst)
> 	    7fcf07ac9e2c [unknown] (/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
> 	    7fcf07aca7c8 [unknown] (/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
> 	    7fcf07acac18 _XtCreateWidget (/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
> 	    7fcf07acaefd XtCreateWidget (/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
> 	          6b01f3 xlw_create_menubar (/tmp/emacs-tst)
> 	          6af1d3 instantiate_widget_instance (/tmp/emacs-tst)
> 	          6ae462 allocate_widget_instance (/tmp/emacs-tst)
> 	          6af306 lw_make_widget (/tmp/emacs-tst)
> 	          6af392 lw_create_widget (/tmp/emacs-tst)
> 	          4974b9 set_frame_menubar (/tmp/emacs-tst)
> 	          497673 initialize_frame_menubar (/tmp/emacs-tst)
> 	          5358f5 Fx_create_frame (/tmp/emacs-tst)
> 
> This font allocation doesn't read or write to the frame cache, and has
> its own font-cleanup call that appears to work. I cannot find any
> explicit evidence that this clears out the font cache, but turning off
> the menu with M-x menu-bar-mode makes this leak mostly go away.

This is in the lwlib library, whose font allocations are AFAIK not
tracked by Emacs's font managing machinery.  With other toolkits, we
don't even know which fonts are used by the menus, and don't handle
nor have access to those fonts.