First you need to run the demo in E2E mode:
pnpm dev:e2eThen, you can use the Chrome DevTools to investigate the memory leak.
You can create a Workbook and then dispose it from Console by running:
E2EControllerAPI.loadAndRelease()And you can take profiles of the application and see if Workbook instances are being retained.
You can also see if the Univer instance is being retained after we dispose it by running in Console:
E2EControllerAPI.disposeUniver()For example: dream-num/univer@6423ff8/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts#L244
HOW TO FIX: Please remember to dispose subscriptions.
It is very common to cause memory leak if you get the current unit in singleton modules and subscribe to it. Singleton modules are defined as modules that are registered in the Univer root injector instead of injectors held by render units.
For example: https://github.com/dream-num/univer/blob/dev/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts#L433.
HOW TO FIX: Please consider extracting the related logic to an IRenderModule instead.
React would keep the dep arrays into memory, so if you put a big object into an array, it would cause memory leak.
For example:
HOW TO FIX: Please consider using unitId in dep arrays instead.
TODO @wzhudev