GNU bug report logs - #45200
Memory leaks: (garbage-collect) fails to reclaim memory

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Konstantin Kharlamov <hi-angel@HIDDEN>; dated Sat, 12 Dec 2020 18:44:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 45200 <at> debbugs.gnu.org:


Received: (at 45200) by debbugs.gnu.org; 12 Dec 2020 20:16:15 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Dec 12 15:16:15 2020
Received: from localhost ([127.0.0.1]:46762 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1koBJP-0001K0-39
	for submit <at> debbugs.gnu.org; Sat, 12 Dec 2020 15:16:15 -0500
Received: from eggs.gnu.org ([209.51.188.92]:53982)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1koBJO-0001Jc-42
 for 45200 <at> debbugs.gnu.org; Sat, 12 Dec 2020 15:16:14 -0500
Received: from fencepost.gnu.org ([2001:470:142:3::e]:51314)
 by eggs.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <eliz@HIDDEN>)
 id 1koBJH-0002dH-DS; Sat, 12 Dec 2020 15:16:08 -0500
Received: from [176.228.60.248] (port=1537 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1koBJG-000875-PR; Sat, 12 Dec 2020 15:16:07 -0500
Date: Sat, 12 Dec 2020 22:15:52 +0200
Message-Id: <83k0tmeq6f.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Konstantin Kharlamov <hi-angel@HIDDEN>
In-Reply-To: <dd4a240ab3ff14d8f04d02b2504611a4d9f3f816.camel@HIDDEN>
 (message from Konstantin Kharlamov on Sat, 12 Dec 2020 21:43:10 +0300)
Subject: Re: bug#45200: Memory leaks: (garbage-collect) fails to reclaim memory
References: <dd4a240ab3ff14d8f04d02b2504611a4d9f3f816.camel@HIDDEN>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 45200
Cc: 45200 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Konstantin Kharlamov <hi-angel@HIDDEN>
> Date: Sat, 12 Dec 2020 21:43:10 +0300
> 
> # Steps to reproduce:
> 
> 1. Run `mkdir /tmp/.emacs.d`
> 2. Run emacs as `HOME=/tmp/ emacs`, and measure its PSS
> 3. Create a file /tmp/.emacs.d/early-init.el with content:
> 
>     ;; only run garbage collection on idle
>     (setq gc-cons-threshold most-positive-fixnum)
>     (run-with-idle-timer 2 t (lambda () (garbage-collect)))
> 
> 4. Run emacs as `HOME=/tmp/ emacs`, evaluate (garbage-collect), then measure its PSS
> 
> ## Expected
> 
> Size has no statistically-significant difference, because in both cases we garbage-collected memory.
> 
> ## Actual
> 
> Size without calling explicit garbage-collect, from 3 runs, varied around 41.2..41.7 MB.
> 
> Size afterwards, also 3 runs, varied around 45.4..45.5 MB.

Could be simply the effect of different stack size, since Emacs's GC
is conservative, and when there's doubt whether something is a live
object, it won't GC it.

I think more specific and detailed evidence is needed to prove your
case: which objects were not GC'ed and why.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#45200; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Dec 2020 18:43:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Dec 12 13:43:23 2020
Received: from localhost ([127.0.0.1]:46507 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ko9rX-0000u4-73
	for submit <at> debbugs.gnu.org; Sat, 12 Dec 2020 13:43:23 -0500
Received: from lists.gnu.org ([209.51.188.17]:38118)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hi-angel@HIDDEN>) id 1ko9rV-0000tw-UO
 for submit <at> debbugs.gnu.org; Sat, 12 Dec 2020 13:43:22 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:41584)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <hi-angel@HIDDEN>)
 id 1ko9rV-0003wd-I9
 for bug-gnu-emacs@HIDDEN; Sat, 12 Dec 2020 13:43:21 -0500
Received: from forward106p.mail.yandex.net ([77.88.28.109]:57409)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <hi-angel@HIDDEN>)
 id 1ko9rS-0002Tr-D0
 for bug-gnu-emacs@HIDDEN; Sat, 12 Dec 2020 13:43:20 -0500
Received: from mxback9g.mail.yandex.net (mxback9g.mail.yandex.net
 [IPv6:2a02:6b8:c03:7aa:0:640:d10:d80f])
 by forward106p.mail.yandex.net (Yandex) with ESMTP id 73FF11C816EE
 for <bug-gnu-emacs@HIDDEN>; Sat, 12 Dec 2020 21:43:11 +0300 (MSK)
Received: from iva8-174eb672ffa9.qloud-c.yandex.net
 (iva8-174eb672ffa9.qloud-c.yandex.net [2a02:6b8:c0c:b995:0:640:174e:b672])
 by mxback9g.mail.yandex.net (mxback/Yandex) with ESMTP id ZktHbZDohB-hBlKKG4K; 
 Sat, 12 Dec 2020 21:43:11 +0300
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail;
 t=1607798591; bh=oxv1AY/uOWizwjT7CWACUwRcNqxVlyMGswP6MDIAXkE=;
 h=To:From:Subject:Message-ID:Date;
 b=fvJ37UX4cPhGpjoZHd1jmR4+Q/RJTiOLQLEnkgzTqS2kWOgqFYZuXlEPQb/74VlAw
 JBWnzEARCupotd5Pjt0VPnpVIAPZKSetO1H1ChSmbkkb4uJVgFdW+8G2cKYGoDsgGb
 R2E1n3mZhyriGoDP/rYPHKORu07AjMCIZ+aozkeY=
Authentication-Results: mxback9g.mail.yandex.net; dkim=pass header.i=@yandex.ru
Received: by iva8-174eb672ffa9.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA
 id XHIvb3LCoV-hAI0l86g; Sat, 12 Dec 2020 21:43:10 +0300
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
 (Client certificate not present)
Message-ID: <dd4a240ab3ff14d8f04d02b2504611a4d9f3f816.camel@HIDDEN>
Subject: Memory leaks: (garbage-collect) fails to reclaim memory
From: Konstantin Kharlamov <hi-angel@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Date: Sat, 12 Dec 2020 21:43:10 +0300
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.38.2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=77.88.28.109; envelope-from=hi-angel@HIDDEN;
 helo=forward106p.mail.yandex.net
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

The problem is basically: (garbage-collect) refuses to collect some of the memory. It is more visible if you delay garbage collection, which is what I do for for performance-related reasons. My config has the following snippet:

    ;; only run garbage collection on idle
    (setq gc-cons-threshold most-positive-fixnum)
    (run-with-idle-timer 2 t (lambda () (garbage-collect)))

How much memory gets lost depends on configuration. For me right after start the difference is 40 MB: ≈60 MB is Emacs PSS size without above code, and ≈100 MB it is when garbage-collection is delayed, *after* I run explicitly (garbage-collect). It is less visible without any other configs, nonetheless it's visible.

# Steps to reproduce:

1. Run `mkdir /tmp/.emacs.d`
2. Run emacs as `HOME=/tmp/ emacs`, and measure its PSS
3. Create a file /tmp/.emacs.d/early-init.el with content:

    ;; only run garbage collection on idle
    (setq gc-cons-threshold most-positive-fixnum)
    (run-with-idle-timer 2 t (lambda () (garbage-collect)))

4. Run emacs as `HOME=/tmp/ emacs`, evaluate (garbage-collect), then measure its PSS

## Expected

Size has no statistically-significant difference, because in both cases we garbage-collected memory.

## Actual

Size without calling explicit garbage-collect, from 3 runs, varied around 41.2..41.7 MB.

Size afterwards, also 3 runs, varied around 45.4..45.5 MB.

This is 4 MB lost. While not much, but as I mentioned it grows as much as to 40MB. The Emacs whose emacslient I'm using to write this email has size 218 MB, and now I wouldn't be surprised if much of that is actually a leaked memory.

# Version

Emacs-git 28.0.50, build from commit abd15e088e99





Acknowledgement sent to Konstantin Kharlamov <hi-angel@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#45200; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 12 Dec 2020 20:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.