Subject: bug#79023: 30.1.90; Suspicion of memory leak on internal_redisplay (MacOS)

From: Przemysław Alexander Kamiński<[email-masked]>
Date: Wed, 16 Jul 2025 14:54:06 +0200

On 16 Jul 2025, at 13:08, Eli Zaretskii wrote:

>> From: Przemysław Alexander Kamiński
>>  <[email-masked]>
>> Cc: [email-masked]
>> Date: Tue, 15 Jul 2025 15:52:20 +0200
>>
>> I've done some extra testing, since I wouldn't be surprised if some 
>> release on a string was missing or something. On a fresh instance 
>> blinking cursor is enough to raise memory usage. 10mb over 4.5mb and 
>> garbage- didn't releaes memory.
>
> Please describe this recipe in more detail, starting from "emacs -Q",
> so others could try repeating it.  Also, please describe how you
> measure the memory leaks and what are the numbers you see.
>

Unfortunatelly there's nothing more I can do, Instruments is strictly 
GUI app. All text has to be extracted manually. I know it's probably the 
worst way to do, but I recorded example session with `emacs -Q`.

https://www.youtube.com/watch?v=_korzyoMXfY

It'd be nice if someone smarter than me and more experienced in MacOS 
system programming took a look on this, my current line is to have a 
build pipeline and throw different ideas until I can find something that 
works.

>> I think I can reproduce test case and even think what might be the 
>> cause, as I looked around MacOS code for couple of minutes.
>
> Please do, and thanks.

I've been able to reproduce by using blinking cursor (setq 
blink-cursor-blinks 0 blink-cursor-interval 0.1).
Attached patch seemed to decrease number of allocations and leaks but 
it's not enough to make a dent.

Best,
Przemysław Alexander Kamiński
diff --git a/src/nsfont.m b/src/nsfont.m
index b8aa6764..f99980b1 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -529,6 +529,10 @@ static void ns_glyph_metrics (struct nsfont_info *font_info,
       chars[95] = '\0';
 
       ascii_printable = [[NSString alloc] initWithFormat: @"%s", chars];
+      if (ascii_printable != nil )
+      {
+        [ascii_printable autorelease];
+      }
     }
 
   if (w < (CGFloat) 0.0)