Skip to content

[GTK4] Memory (and threads) leak in Shell #2741

@jonahgraham

Description

@jonahgraham

Describe the bug

SWT on GTK4 does not dispose the native resources allocated by the Shell.

To Reproduce

Run the below example with a process monitor running

package org.eclipse.swt.snippets;

import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.widgets.*;

public class Snippet1 {

	public static void main(String[] args) {
		System.out.println("GTK4: " + GTK.GTK4);
		int i = 0;
		while (i++ < 2500000) {
			System.out.println(i);
			final Display display = new Display();
			Shell shell = new Shell(display);
			shell.open(); // only needed on wayland
			while (display.readAndDispatch()) {
			}
			display.dispose();
			System.gc();
		}
	}
}

Expected behavior

No memory or thread growth after first few iterations - the GTK3 version achieves this.

Screenshots

(apologies for the picture of my screen, while tests were running I couldn't get screenshots working)

Image shows, the following java processes. The snippet above was running for about 3 minutes, or about 600 iterations.

  1. My IDE
  2. GTK4 x11 of above snippet
  3. GTK3 x11 of above snippet
  4. GTK4 wayland of above snippet

Image

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)

Ubuntu 25.10


In addition to the obvious problem of a memory leak, this is one of the blockers for getting #2714 complete because the test java process keeps running out of memory and the GitHub runner gets killed for trying to allocate too much memory.

Metadata

Metadata

Assignees

Labels

gtk4GTK4 issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions