Skip to content

Commit

Permalink
Memory leak fix (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen authored Jan 5, 2020
1 parent 934352a commit fa2074b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
return highlightTextFill;
}

private final Paragraph<PS, SEG, S> paragraph;
private Paragraph<PS, SEG, S> paragraph;

private final CustomCssShapeHelper<Paint> backgroundShapeHelper;
private final CustomCssShapeHelper<BorderAttributes> borderShapeHelper;
Expand Down Expand Up @@ -221,11 +221,18 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
}

void dispose() {
// this removes listeners (in selections and carets listeners) and avoids memory leaks
selections.removeListener( selectionPathListener );
carets.removeListener( caretNodeListener );
selections.clear();
carets.clear();
selections.clear();
// The above must be before the below to prevent any memory leaks.
// Then remove listeners to also avoid memory leaks.
selections.removeListener( selectionPathListener );
carets.removeListener( caretNodeListener );

getChildren().stream().filter( n -> n instanceof TextExt ).map( n -> (TextExt) n )
.forEach( t -> JavaFXCompatibility.Text_selectionFillProperty(t).unbind() );

getChildren().clear();
paragraph = null;
}

public Paragraph<PS, SEG, S> getParagraph() {
Expand Down

0 comments on commit fa2074b

Please sign in to comment.