From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: Memory leak in keyboard variables? Date: Sat, 20 Dec 2008 09:45:37 -0800 (PST) Message-ID: <200812201745.mBKHjbUh027877@mothra.ics.uci.edu> References: <87d4fzh0qc.fsf@cyd.mit.edu> <87y6ymiw93.fsf@cyd.mit.edu> <8763lqcuju.fsf@stupidchicken.com> <87bpvccirc.fsf@cyd.mit.edu> <877i5z1kka.fsf@xemacs.org> <87ocz7pqbj.fsf@cyd.mit.edu> <494D10A1.1000905@swipnet.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1229795171 24331 80.91.229.12 (20 Dec 2008 17:46:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Dec 2008 17:46:11 +0000 (UTC) Cc: Chong Yidong , "Stephen J. Turnbull" , Markus Triska , emacs-devel@gnu.org To: Jan =?utf-8?Q?Dj=C3=A4rv?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 20 18:47:17 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LE5uz-0002Hq-5Q for ged-emacs-devel@m.gmane.org; Sat, 20 Dec 2008 18:47:16 +0100 Original-Received: from localhost ([127.0.0.1]:38690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LE5tm-0000mf-Nv for ged-emacs-devel@m.gmane.org; Sat, 20 Dec 2008 12:45:58 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LE5th-0000lz-Fy for emacs-devel@gnu.org; Sat, 20 Dec 2008 12:45:53 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LE5te-0000ln-7a for emacs-devel@gnu.org; Sat, 20 Dec 2008 12:45:52 -0500 Original-Received: from [199.232.76.173] (port=43005 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LE5te-0000lk-2e for emacs-devel@gnu.org; Sat, 20 Dec 2008 12:45:50 -0500 Original-Received: from barrelv2.ics.uci.edu ([128.195.1.114]:60498) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1LE5td-000867-IR for emacs-devel@gnu.org; Sat, 20 Dec 2008 12:45:49 -0500 Original-Received: from mothra.ics.uci.edu (mothra.ics.uci.edu [128.195.6.93]) by barrelv2.ics.uci.edu (8.13.8+Sun/8.13.8) with ESMTP id mBKHjdwi026927; Sat, 20 Dec 2008 09:45:39 -0800 (PST) Original-Received: (from dann@localhost) by mothra.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id mBKHjbUh027877; Sat, 20 Dec 2008 09:45:37 -0800 (PST) In-Reply-To: <494D10A1.1000905@swipnet.se> ("Jan =?utf-8?Q?Dj=C3=A4rv=22's?= message of "Sat, 20 Dec 2008 16:34:57 +0100") Original-Lines: 137 X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: mBKHjdwi026927 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-0.34, required 5, autolearn=disabled, ALL_TRUSTED -1.44, FM_MULTI_ODD2 1.10) X-ICS-MailScanner-From: dann@mothra.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:107130 Archived-At: Jan Dj=C3=A4rv writes: > Chong Yidong skrev: > > "Stephen J. Turnbull" writes: > >=20 > >> Chong Yidong writes: > >> > Markus Triska writes: > >> >=20 > >> > > Please also try emacsclient with "-c" instead of "-t" - there s= eems to > >> > > be a probably different and still quite big leak there as will. > >> >=20 > >> > With the recent fix to font_clear_cache, the leak is reduced to 3= 0-40k > >> > per frame. This leak seems to be tied to GTK and X toolkits some= how. > >> > It does not appear when Emacs is compiled with --with-x-toolkit= =3Dno. > >> > >> The toolkits undoubtedly do their own font caching, and probably won= 't > >> release the space until Emacs exits. > >=20 > > Yes, this is a possibility. > >=20 > > Another data point: the leak occurs when the menu-bar is enabled, but > > not when the menu-bar is disabled. It's not necessary to see the leak > > using Emacsclient, as ordinary frame creating/deletion shows it: > >=20 > > (dotimes (i 15) > > (let* ((params '((window-system . x) > > (menu-bar-lines . 1) > > (tool-bar-lines . 1))) > > frame) > > (setq frame (x-create-frame params)) > > (delete-frame frame) > > (garbage-collect))) > >=20 > > I have not been able to track down the source of this leak within Ema= cs. > > As far as I can tell, the existing menu-bar items allocation functions > > (in xmenu.c, menu.c, keyboard.c, and gtkutil.c) free all the memory t= hey > > allocate, yet about 10k of memory remains unfreed with each frame > > created. > >=20 >=20 > From what I see, the frames aren't garabge collected, and then neither = is the > menu bar items in f->menu_bar_vector, which isn't used for the non-tool= kit case. >=20 > The frame is at least referenced from recent-keys, and maybe one more p= lace > which I haven't found. >=20 > Setting f->menu_bar_vector to Qnil when deleting the frame improves the > situation quite a bit, I'm not sure if it totally eliminates the leak. = I've > checked in that change. Following that logic, maybe all Lisp_Objects in struct frame need to be set= to nil. I did that: Index: frame.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/src/frame.c,v retrieving revision 1.402 diff -u -3 -p -u -p -r1.402 frame.c --- frame.c 20 Dec 2008 15:59:50 -0000 1.402 +++ frame.c 20 Dec 2008 17:41:35 -0000 @@ -1632,6 +1628,27 @@ But FORCE inhibits this too. */) kb->Vdefault_minibuffer_frame =3D Qnil; } =20 + f->name =3D Qnil; + f->icon_name =3D Qnil; + f->title =3D Qnil; + f->focus_frame =3D Qnil; + f->root_window =3D Qnil; + f->selected_window =3D Qnil; + f->minibuffer_window =3D Qnil; + f->param_alist =3D Qnil; + f->scroll_bars =3D Qnil; + f->condemned_scroll_bars =3D Qnil; + f->menu_bar_items =3D Qnil; + f->face_alist =3D Qnil; + f->buffer_predicate =3D Qnil; + f->buffer_list =3D Qnil; + f->buried_buffer_list =3D Qnil; + f->menu_bar_window =3D Qnil; + f->tool_bar_window =3D Qnil; + f->tool_bar_items =3D Qnil; + f->desired_tool_bar_string =3D Qnil; + f->current_tool_bar_string =3D Qnil; + /* Cause frame titles to update--necessary if we now have just one frame= . */ update_mode_lines =3D 1; =20 and now this version of the test code above: (dotimes (i 15) (let* ((params '((window-system . nil) (menu-bar-lines . 1) (tool-bar-lines . 1))) frame) (setq frame (x-create-frame params)) (delete-frame frame) (with-current-buffer "*scratch*" (insert (format "%S\n" (garbage-collect)))))) shows: ((66416 . 11688) (13589 . 0) (688 . 250) 147723 356072 (122 . 9) (455 . 907= ) (8425 . 3608)) ((66423 . 11306) (13589 . 0) (688 . 247) 147717 356093 (122 . 9) (456 . 906= ) (8424 . 3609)) ((66425 . 11304) (13589 . 0) (688 . 247) 147717 356114 (122 . 9) (457 . 905= ) (8424 . 3609)) ((66427 . 11302) (13589 . 0) (688 . 247) 147717 356135 (122 . 9) (458 . 904= ) (8424 . 3609)) ((66429 . 11300) (13589 . 0) (688 . 247) 147717 356156 (122 . 9) (459 . 903= ) (8424 . 3609)) ((66431 . 11298) (13589 . 0) (688 . 247) 147717 356177 (122 . 9) (460 . 902= ) (8424 . 3609)) ((66433 . 11296) (13589 . 0) (688 . 247) 147717 356198 (122 . 9) (461 . 901= ) (8424 . 3609)) ((66435 . 11294) (13589 . 0) (688 . 247) 147717 356219 (122 . 9) (462 . 900= ) (8424 . 3609)) ((66437 . 11292) (13589 . 0) (688 . 247) 147717 356240 (122 . 9) (463 . 899= ) (8424 . 3609)) ((66439 . 11290) (13589 . 0) (688 . 247) 147717 356261 (122 . 9) (464 . 898= ) (8424 . 3609)) ((66441 . 11288) (13589 . 0) (688 . 247) 147717 356282 (122 . 9) (465 . 897= ) (8424 . 3609)) ((66443 . 11286) (13589 . 0) (688 . 247) 147717 356303 (122 . 9) (466 . 896= ) (8424 . 3609)) ((66445 . 11284) (13589 . 0) (688 . 247) 147717 356324 (122 . 9) (467 . 895= ) (8424 . 3609)) ((66447 . 11282) (13589 . 0) (688 . 247) 147717 356345 (122 . 9) (468 . 894= ) (8424 . 3609)) ((66449 . 11280) (13589 . 0) (688 . 247) 147717 356366 (122 . 9) (469 . 893= ) (8424 . 3609)) before the above change it was showing: ((66496 . 11612) (13589 . 0) (691 . 250) 147758 356390 (123 . 8) (455 . 907= ) (8431 . 3602)) ((66593 . 11390) (13589 . 0) (695 . 243) 147800 356777 (123 . 8) (456 . 906= ) (8437 . 3596)) ((66685 . 11298) (13589 . 0) (699 . 243) 147848 357164 (123 . 8) (457 . 905= ) (8444 . 3589)) ((66777 . 11206) (13589 . 0) (703 . 243) 147896 357551 (123 . 8) (458 . 904= ) (8451 . 3582)) ((66869 . 11114) (13589 . 0) (707 . 243) 147944 357938 (123 . 8) (459 . 903= ) (8458 . 3575)) ((66961 . 11022) (13589 . 0) (711 . 243) 147992 358325 (123 . 8) (460 . 902= ) (8465 . 3568)) ((67053 . 10930) (13589 . 0) (715 . 243) 148040 358712 (123 . 8) (461 . 901= ) (8472 . 3561)) ((67145 . 10838) (13589 . 0) (719 . 243) 148088 359099 (123 . 8) (462 . 900= ) (8479 . 3554)) ((67237 . 10746) (13589 . 0) (723 . 243) 148136 359486 (123 . 8) (463 . 899= ) (8486 . 3547)) ((67329 . 10654) (13589 . 0) (727 . 201) 148184 359873 (123 . 8) (464 . 898= ) (8493 . 3540)) ((67421 . 10562) (13589 . 0) (731 . 201) 148232 360260 (123 . 8) (465 . 897= ) (8500 . 3533)) ((67513 . 10470) (13589 . 0) (735 . 201) 148280 360647 (123 . 8) (466 . 896= ) (8507 . 3526)) ((67605 . 10378) (13589 . 0) (739 . 201) 148328 361034 (123 . 8) (467 . 895= ) (8514 . 3519)) ((67697 . 10286) (13589 . 0) (743 . 201) 148376 361421 (123 . 8) (468 . 894= ) (8521 . 3512)) ((67789 . 10194) (13589 . 0) (747 . 201) 148424 361808 (123 . 8) (469 . 893= ) (8528 . 3505))