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

Remove listeners in RedoAction for memory efficiency #11839

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/java/org/jabref/gui/undo/RedoAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.jabref.gui.undo;

import java.util.Optional;
import java.util.function.Supplier;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.WeakChangeListener;
import javax.swing.undo.CannotRedoException;

import org.jabref.gui.DialogService;
Expand All @@ -21,11 +24,15 @@ public RedoAction(Supplier<LibraryTab> tabSupplier, DialogService dialogService,
this.tabSupplier = tabSupplier;
this.dialogService = dialogService;

// TODO: The old listener should be removed. Otherwise, memory consumption will increase.
stateManager.activeTabProperty().addListener((observable, oldValue, activeLibraryTab) -> {
ChangeListener<Optional<LibraryTab>> listener = (observable, oldValue, activeLibraryTab) -> {
activeLibraryTab.ifPresent(libraryTab ->
this.executable.bind(libraryTab.getUndoManager().getRedoableProperty()));
});
this.executable.bind(libraryTab.getUndoManager().getRedoableProperty()));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This empty line is not necessary, is it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this empty line is for exists to separate lines 30 and 32 from each other. But I can remove.

oldValue.ifPresent(libraryTab -> this.executable.unbind());
};

WeakChangeListener<Optional<LibraryTab>> weakListener = new WeakChangeListener<>(listener);
stateManager.activeTabProperty().addListener(weakListener);
}

@Override
Expand Down
Loading