How to manage memory in case of multiple fabric js canvas?

前端 未结 1 712
南方客
南方客 2021-02-04 18:45

In my application, I have multiple Fabric.js canvases, There is no limit on the number of canvases. I\'ll render heavy JSON via loadFromJson method of Fabric.js.

1条回答
  •  情话喂你
    2021-02-04 18:48

    You might be interested in 3 things (in the order of significance/destruction):

    1. canvas.clear() — removes all canvas objects from it.

    2. canvas.dispose() — removes all canvas objects AND removes all event listeners

    3. $(canvas.wrapperEl).remove() (using jQuery for illustrative purposes) — to remove canvas wrapper element (which contains upper and lower canvases used by Fabric). This can be done AFTER you call dispose, if the goal is to completely remove Fabric canvas from a document.

    0 讨论(0)
提交回复
热议问题