Skip to content

Commit

Permalink
close bitmap when looker destroys
Browse files Browse the repository at this point in the history
  • Loading branch information
sashankaryal committed Nov 22, 2024
1 parent c869b1c commit e5eb5de
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/packages/looker/src/lookers/abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ export abstract class AbstractLooker<
return;
}

if (this.state.destroyed && this.sampleOverlays) {
// close all current overlays
this.pluckedOverlays.forEach((overlay) => overlay.cleanup?.());
}

if (
!this.state.windowBBox ||
this.state.destroyed ||
Expand Down
1 change: 1 addition & 0 deletions app/packages/looker/src/overlays/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface Overlay<State extends Partial<BaseState>> {
getPoints(state: Readonly<State>): Coordinates[];
getSelectData(state: Readonly<State>): SelectData;
getSizeBytes(): number;
cleanup?(): void;
}

export abstract class CoordinateOverlay<
Expand Down
8 changes: 7 additions & 1 deletion app/packages/looker/src/overlays/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default class DetectionOverlay<
> extends CoordinateOverlay<State, DetectionLabel> {
private is3D: boolean;
private labelBoundingBox: BoundingBox;
private imageBitmap: ImageBitmap | null = null;

constructor(field, label) {
super(field, label);
Expand Down Expand Up @@ -261,6 +260,13 @@ export default class DetectionOverlay<
const oh = state.strokeWidth / state.canvasBBox[3];
return [(bx - ow) * w, (by - oh) * h, (bw + ow * 2) * w, (bh + oh * 2) * h];
}

public cleanup(): void {
if (this.label.mask?.bitmap) {
this.label.mask?.bitmap.close();
console.log(">>>cleanup");
}
}
}

export const getDetectionPoints = (labels: DetectionLabel[]): Coordinates[] => {
Expand Down
6 changes: 6 additions & 0 deletions app/packages/looker/src/overlays/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ export default class HeatmapOverlay<State extends BaseState>
getSizeBytes(): number {
return sizeBytesEstimate(this.label);
}

public cleanup(): void {
if (this.label.map?.bitmap) {
this.label.map?.bitmap.close();
}
}
}

export const getHeatmapPoints = (labels: HeatmapLabel[]): Coordinates[] => {
Expand Down
6 changes: 6 additions & 0 deletions app/packages/looker/src/overlays/segmentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ export default class SegmentationOverlay<State extends BaseState>
getSizeBytes(): number {
return sizeBytesEstimate(this.label);
}

public cleanup(): void {
if (this.label.mask?.bitmap) {
this.label.mask?.bitmap.close();
}
}
}

export const getSegmentationPoints = (
Expand Down

0 comments on commit e5eb5de

Please sign in to comment.