Skip to content

Bug:ImGui-java Causing Memory Leak with Specific UI Sort/Layout #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Xinkong-xk opened this issue May 2, 2025 · 4 comments
Open

Bug:ImGui-java Causing Memory Leak with Specific UI Sort/Layout #332

Xinkong-xk opened this issue May 2, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Xinkong-xk
Copy link

Version

1.89.0 (new) and 1.86.12 (old)

What happened?

A bug happened!
I am not sure how this bug occurs, and I haven't been able to identify a consistent pattern for its appearance. The issue manifests as a rapid increase in the number of “java.nio.DirectIntBufferU” objects after building the UI in a certain way, eventually leading to a memory leak.

I have observed this bug in multiple versions. I first discovered it accidentally while using version 1.86.12. Later, I upgraded to 1.89.0 and switched to using imgui-app as the windowing platform for testing, but the bug still occurred.

This bug does not cause any exceptions or crashes, but it leads to a continuous and significant increase in memory usage. I directly copied the initial test code recommended on the imgui-java homepage, and then added 6 windows along with several ImGui.text calls. I noticed that this bug only occurs when these windows and text calls are arranged in a certain specific pattern. For example, if I remove the last window (Window 6), the bug disappears. Therefore, I cannot summarize a consistent pattern that triggers the bug.

Image

Image

Reproduction

import imgui.ImGui;
import imgui.app.Application;
import imgui.app.Configuration;

// From the home page of imgui-java 
public class Main extends Application {
	@Override
	protected void configure(Configuration config) {
		config.setTitle("Dear ImGui is Awesome!");
	}

	@Override
	public void process() {
		// window 1
		imgui.internal.ImGui.begin("a1");
		// end
		imgui.ImGui.end();

		// window 2
		if (imgui.internal.ImGui.begin("a2")) {
			imgui.internal.ImGui.text("1");
		}
		// end
		imgui.ImGui.end();

		// window 3
		if (imgui.internal.ImGui.begin("a3")) {
			imgui.internal.ImGui.text("2");
		}
		// end
		imgui.ImGui.end();

		// window 4
		if (imgui.internal.ImGui.begin("a4")) {
			imgui.internal.ImGui.text("3");
		}
		// end
		imgui.ImGui.end();

		// window 5
		imgui.internal.ImGui.begin("a5");
		// end
		imgui.ImGui.end();

		// window 6
		imgui.internal.ImGui.begin("a6");
		// end
		imgui.ImGui.end();
	}

	public static void main(String[] args) {
		launch(new Main());
	}
}

Relevant log output

// No error but memory leak.
// Object Type : "java.nio.DirectIntBufferU"
// Tool : Jprofiler , IDEA
@Xinkong-xk Xinkong-xk added the bug Something isn't working label May 2, 2025
@Xinkong-xk
Copy link
Author

Is this a bug caused by my incorrect coding?

@Xinkong-xk Xinkong-xk changed the title Bug: Bug:ImGui-java Causing Memory Leak with Specific UI Sort/Layout May 2, 2025
@Xinkong-xk
Copy link
Author

Is anybody there?

@SpaiR
Copy link
Owner

SpaiR commented May 9, 2025

It's hard to say anything specific about your problem. The code looks ok, so the issue just need an investigation.

@Xinkong-xk
Copy link
Author

I’m not sure if this bug is caused by my device or system. This is the result of my testing. If you have time, you can also try running that code and use Task Manager or Java monitoring tools to check if there are any abnormal memory leaks. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants