Skip to content

Commit

Permalink
Reduced memory usage, not a leak, but purge ImageView and it's data w…
Browse files Browse the repository at this point in the history
…hen not needed.
  • Loading branch information
ccavanaugh committed Aug 26, 2018
1 parent ea4adf5 commit 903b30e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions jgnash-fx/src/main/java/jgnash/uifx/control/BusyPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class BusyPane extends StackPane {

private final ImageView imageView;
private ImageView imageView;

private final Label messageLabel;

Expand All @@ -55,10 +55,6 @@ public class BusyPane extends StackPane {

public BusyPane() {

imageView = new ImageView();
imageView.setFocusTraversable(false);
imageView.setEffect(new BoxBlur(4, 4, 2));

progressIndicator = new ProgressIndicator();
messageLabel = new Label();

Expand All @@ -78,6 +74,16 @@ public BusyPane() {
setVisible(false);
}

private ImageView getImageView() {
ImageView imageView = new ImageView();
imageView.setFocusTraversable(false);
imageView.setEffect(new BoxBlur(4, 4, 2));

imageView.setImage(getScene().getRoot().snapshot(null, null));

return imageView;
}

private void updateFont() {
messageLabel.fontProperty().set(Font.font(null, FontWeight.BOLD, null,
ThemeManager.getBaseTextHeight() * 1.2));
Expand All @@ -88,7 +94,15 @@ public void setTask(@Nullable final Task<?> task) {
setVisible(false);
progressIndicator.progressProperty().unbind();
messageLabel.textProperty().unbind();
getChildren().remove(imageView);

imageView.setImage(null); // don't retain the image, conserve memory
imageView = null;
} else {

// get the snapshot
imageView = getImageView();

messageLabel.textProperty().bind(task.messageProperty());
progressIndicator.progressProperty().bind(task.progressProperty());

Expand All @@ -104,12 +118,10 @@ public void setTask(@Nullable final Task<?> task) {

@Override protected void layoutChildren() {
super.layoutChildren();

if (getParent() != null && isVisible()) {
setVisible(false);
getChildren().remove(imageView);

imageView.setImage(getScene().getRoot().snapshot(null, null));

getChildren().add(imageView);
imageView.toBack();
setVisible(true);
Expand Down

0 comments on commit 903b30e

Please sign in to comment.