From bf7772e258cafe8bccf4e00967d69a88efb7438e Mon Sep 17 00:00:00 2001 From: Wenzhao Hu <12122021+wzhudev@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:18:09 +0800 Subject: [PATCH] fix: fix memory leak in skeleton manager and image cropper --- .../src/controllers/image-cropper.controller.ts | 10 +++++----- .../src/services/sheet-skeleton-manager.service.ts | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/drawing-ui/src/controllers/image-cropper.controller.ts b/packages/drawing-ui/src/controllers/image-cropper.controller.ts index 6a5a586f638..b78b2b70ecb 100644 --- a/packages/drawing-ui/src/controllers/image-cropper.controller.ts +++ b/packages/drawing-ui/src/controllers/image-cropper.controller.ts @@ -23,7 +23,7 @@ import { MessageType } from '@univerjs/design'; import { getDrawingShapeKeyByDrawingSearch, IDrawingManagerService, SetDrawingSelectedOperation } from '@univerjs/drawing'; import { CURSOR_TYPE, degToRad, Image, IRenderManagerService, precisionTo, Vector2 } from '@univerjs/engine-render'; import { IMessageService } from '@univerjs/ui'; -import { filter, switchMap } from 'rxjs'; +import { of, switchMap } from 'rxjs'; import { AutoImageCropOperation, CloseImageCropOperation, CropType, OpenImageCropOperation } from '../commands/operations/image-crop.operation'; import { ImageCropperObject } from '../views/crop/image-cropper-object'; @@ -334,14 +334,14 @@ export class ImageCropperController extends Disposable { imageCropperObject?.dispose(); }) ); - const sheetUnit = this._univerInstanceService + + const sheetUnit$ = this._univerInstanceService .getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET) .pipe( - filter((workbook) => Boolean(workbook)), - switchMap((workbook) => workbook!.activeSheet$) + switchMap((workbook) => workbook ? workbook.activeSheet$ : of(null)) ); - this.disposeWithMe(sheetUnit.subscribe(() => { + this.disposeWithMe(sheetUnit$.subscribe(() => { this._commandService.syncExecuteCommand(CloseImageCropOperation.id); })); } diff --git a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts index bf3ec97cb3d..7225b47d4e2 100644 --- a/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts +++ b/packages/sheets-ui/src/services/sheet-skeleton-manager.service.ts @@ -67,8 +67,9 @@ export class SheetSkeletonManagerService extends Disposable implements IRenderMo this.disposeWithMe(() => { this._currentSkeletonBefore$.complete(); this._currentSkeleton$.complete(); - this._sheetSkeletonParamStore = new Map(); - this._sheetSkService.deleteSkeleton(this._context.unitId, this._sheetId); + + this._sheetSkeletonParamStore.forEach((sk) => this.disposeSkeleton(sk.sheetId)); + this._sheetSkeletonParamStore.clear(); }); this._initRemoveSheet();