From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to debug elisp memory leak Date: Fri, 17 Sep 2004 18:14:28 GMT Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <2hzn3qz30q.fsf@vserver.cs.uit.no> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1095444875 17568 80.91.229.6 (17 Sep 2004 18:14:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 17 Sep 2004 18:14:35 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Sep 17 20:14:23 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1C8NFX-0007Cp-00 for ; Fri, 17 Sep 2004 20:14:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1C8NLG-00006P-S9 for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Sep 2004 14:20:18 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!nntp.giganews.com!nf3.bellglobal.com!snoopy.risq.qc.ca!charlie.risq.qc.ca!53ab2750!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3.50 (gnu/linux) Cancel-Lock: sha1:W3jFP1CSt0INWE4JKhbDnGcTF5g= Original-Lines: 133 Original-NNTP-Posting-Host: 132.204.24.84 Original-X-Complaints-To: abuse@umontreal.ca Original-X-Trace: charlie.risq.qc.ca 1095444868 132.204.24.84 (Fri, 17 Sep 2004 14:14:28 EDT) Original-NNTP-Posting-Date: Fri, 17 Sep 2004 14:14:28 EDT Original-Xref: shelby.stanford.edu gnu.emacs.help:125383 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:20738 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:20738 > I'm regularly getting the "lisp pointer size exceeded" warning after > about one week of running emacs. When this happens, nothing I do, such > as killing buffers, seems to help much; at most I can postpone the > inevitable crash for a few more minutes of work. > I figure there's a memory leak; somewhere there's e.g a global > variable with an ever-growing list of whatever. But I have no idea > where to start looking for what or where this might be. Can anyone > help me? > I'm using GNU Emacs 21.3.1, but this behavior has been consistent for > at least a few months and minor versions of Emacs. I don't think there's a quick answer to this. But for a start, can you try the pckage below? It provides a command M-x memory-usage which will show what Emacs's heap is made of (whic proportion is cons cells, buffer text, strings, arrays, ...). It's not much info, but it's a start: when you get the "lisp pointer size exceeded" thingy, hit M-x memory-usage and post the result here. Also, try then to kill (lots of or even all) buffers and re-run M-x memory-usage and post that result as well. Stefan PS: Better to hit M-x memory-usage at least once before to make sure it works and is already loaded and ready to be used. ;;; memory-usage.el --- Analyze the memory usage of Emacs in various ways ;; Copyright (C) 2002, 2004 Free Software Foundation, Inc. ;; Author: Stefan Monnier ;; Keywords: maint ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;;; Code: (defun buffer-size-bytes (b) "Return total number of bytes in the buffer contents." (with-current-buffer b (save-restriction (widen) (- (position-bytes (point-max)) (position-bytes (point-min)))))) (defun buffer-gap-bytes (b) "Return total number of bytes in the buffer gap." (with-current-buffer b (gap-size))) (defun buffer-total-bytes (b) "Return total number of ralloc bytes used by buffer." (with-current-buffer b (save-restriction (widen) (+ (position-bytes (point-max)) (- (position-bytes (point-min))) (gap-size))))) ;;;###autoload (defun memory-usage () "List all buffers and their memory usage." (interactive) (pop-to-buffer (get-buffer-create "*Buffer Details*")) (erase-buffer) (let* ((bufs (buffer-list)) (num (length bufs)) (gc-stats (garbage-collect)) (conses (nth 0 gc-stats)) (symbols (nth 1 gc-stats)) (markers (nth 2 gc-stats)) (strings (nth 3 gc-stats)) (vectors (nth 4 gc-stats)) (floats (nth 5 gc-stats)) (intervals (nth 6 gc-stats))) (insert (format "Garbage collection stats:\n%s\n\n =>" gc-stats)) (insert (format "\t%d bytes in cons cells\n" (* 8 (+ (car conses) (cdr conses))))) (insert (format "\t%d bytes in symbols\n" (* 24 (+ (car symbols) (cdr symbols))))) (insert (format "\t%d bytes in markers\n" (* 20 (+ (car markers) (cdr markers))))) (insert (format "\t%d bytes of string chars\n" strings)) (insert (format "\t%d bytes of vector slots\n" (* 4 vectors))) (insert (format "\t%d bytes in floats\n" (* 12 (+ (car floats) (cdr floats))))) (insert (format "\t%d bytes in intervals\n" (* 28 (+ (car intervals) (cdr intervals))))) (insert (format "\nTotal bytes in lisp objects (not counting string and vector headers): %d\n\n" (+ (* 8 (+ (car conses) (cdr conses))) (* 24 (+ (car symbols) (cdr symbols))) (* 20 (+ (car markers) (cdr markers))) strings vectors (* 12 (+ (car floats) (cdr floats))) (* 28 (+ (car intervals) (cdr intervals)))))) (insert (format "Buffer ralloc memory usage:\n%d buffers\n%d bytes total (%d in gaps)\n" num (apply #'+ (mapcar #'buffer-total-bytes bufs)) (apply #'+ (mapcar #'buffer-gap-bytes bufs)))) (insert (format "%10s\t%s\t%s\n\n" "Size" "Gap" "Name")) (insert (mapconcat (lambda (b) (format "%10d\t%s\t%s" (buffer-size-bytes b) (buffer-gap-bytes b) (buffer-name b))) (sort bufs (lambda (b1 b2) (> (buffer-size-bytes b1) (buffer-size-bytes b2)))) "\n")) (insert "\n")) (goto-char (point-min))) (provide 'memory-usage) ;; arch-tag: 04e012f0-3c59-4319-8d1a-e86204671ec5 ;;; memory-usage.el ends here