Skip to content

Commit

Permalink
dispose of labels when clearing the cache, #64
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 5, 2024
1 parent 1b97066 commit 2d55d7b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion js/TickLabelSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,21 @@ class TickLabelSet extends Path {
* symbolic labels (e.g. '2L').
*/
public invalidateTickLabelSet(): void {
this.labelMap.clear();
this.clearCache();
this.update();
}

/**
* Clears the cache. It is also our responsibility to dispose all labels in the cache, because they were
* created by calling createLabel.
*/
private clearCache(): void {
for ( const label of this.labelMap.values() ) {
label && label.dispose();
}
this.labelMap.clear();
}

public setCreateLabel( createLabel: ( value: number ) => Node | null ): void {
this.createLabel = createLabel;
this.invalidateTickLabelSet();
Expand Down

0 comments on commit 2d55d7b

Please sign in to comment.