Skip to content
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

Windows menu retains reference to removed stages #27

Open
brucejohnson opened this issue Apr 29, 2024 · 0 comments
Open

Windows menu retains reference to removed stages #27

brucejohnson opened this issue Apr 29, 2024 · 0 comments

Comments

@brucejohnson
Copy link

brucejohnson commented Apr 29, 2024

I've had a problem recently where the video memory of canvases in my JavaFX stages is not released when I remove the stage and I run out of memory.
The problem goes away if I remove (along with a few other things in my code) the use of autoAddWindowMenuItems for the Window menu.

I think the problem is from the following methods in WindowMenuUpdateListener.

addWindowMenuItem adds a reference to the stage in createdMenuItems, but removeWindowMenuItem doesn't remove it.
So even though you remove the stage it isn't properly garbage collected as there is still a reference to it.

private void removeWindowMenuItem(Stage stage, Menu menu) {
	MenuItem menuItem = createdMenuItems.get(stage);
	if (menuItem != null) {
               menu.getItems().remove(menuItem);
           }
}

private void addWindowMenuItem(Stage stage, Menu menu) {
	CheckMenuItem item = new CheckMenuItem(stage.getTitle());
	item.setOnAction(event -> stage.toFront());
	createdMenuItems.put(stage, item);
	menu.getItems().add(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant