Skip to content
Merged
Changes from all commits
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
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