Subject: bug#75636: closed (Re: bug#75636: GTK memory leaks)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 01 Feb 2025 23:32:02 +0000

Your bug report

#75636: GTK memory leaks

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
75636: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75636
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#75636: GTK memory leaks
From: Pip Cet <[email-masked]>
To: Po Lu <[email-masked]>
Cc: [email-masked]
Date: Sat, 01 Feb 2025 23:31:19 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Pip Cet <[email-masked]> writes:

> "Po Lu" <[email-masked]> writes:
>
>>> commit 5ed4aaa986dbf75f8565f4d8cdd3d1d1b38b6142 (HEAD)
>>> Author: Pip Cet <[email-masked]>
>>>
>>>     Destroy GTK tool bar widget if it was never attached (bug#75636)
>>>
>>>     * src/gtkutil.c (xg_free_frame_widgets): Call gtk_widget_destroy on an
>>>     unpacked toolbar widget.
>>>
>>> diff --git a/src/gtkutil.c b/src/gtkutil.c
>>> index 0e9dd4dfe11..97582a524da 100644
>>> --- a/src/gtkutil.c
>>> +++ b/src/gtkutil.c
>>> @@ -1885,6 +1885,12 @@ xg_free_frame_widgets (struct frame *f)
>>>        if (tbinfo)
>>>          xfree (tbinfo);
>>>
>>> +      if (x->toolbar_widget && !x->toolbar_is_packed)
>>> +	{
>>> +	  gtk_widget_destroy (x->toolbar_widget);
>>> +	  x->toolbar_widget = NULL;
>>> +	}
>>> +
>>>        /* x_free_frame_resources should have taken care of it */
>>>  #ifndef HAVE_PGTK
>>>  #ifdef HAVE_XDBE
>>
>> LGTM.
>
> Thanks, pushed.

While GTK remains very slow due to MPS limitations and the way we work
around them, I'll file a new bug when we have a way around that, and
closing this one.  Thanks!

Pip

Subject: GTK memory leaks
From: Pip Cet <[email-masked]>
To: [email-masked], Po Lu <[email-masked]>
Date: Fri, 17 Jan 2025 20:15:02 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Creating and destroying GTK frames (using gtkutil.c, not PGTK) currently
leaks some memory, particularly when using tool bars.

1. The input "multicontext" created by:

  imc = gtk_im_multicontext_new ();
  g_object_ref (imc);

is only unref'd once when destroying the frame.  This leaves the
refcount at 1 and leaks the object.

2. free_frame_tool_bar is never called in my experiments, so the toolbar
widget isn't destroyed.

This isn't usually a problem because it's just a small memory leak, but
on the feature/igc branch, user data passed to glib must be protected in
a special GC root structure; such structures accumulate when running in
GTK, eventually reducing GC performance significantly.

Unfortunately, valgrind doesn't seem to catch these memory leaks.