tldraw icon indicating copy to clipboard operation
tldraw copied to clipboard

[Bug]: Memory leak when deleting a page or image

Open c1DeepInside opened this issue 2 years ago • 4 comments

What happened?

I am ready to implement the fix of this problem

Issue with Page Deletion:

While integrating tldraw into my application that interacts with a database, I've noticed that deleting a page (either via Editor.deletePage() or through the tldraw UI) does not remove the associated shapes from the memory store. This poses a significant problem as these lingering objects in memory can impact the performance and data management of my application.

Issue with Asset Deletion

Similarly, when images are loaded and then deleted, the associated shapes are removed, but the assets remain in memory. This accumulation of data in memory can adversely affect the performance of my application, especially in its interaction with the database.

// ... (omitted details for brevity)

const snapshot = store.getSnapshot();
console.log('before', snapshot.length);

// Code to simulate adding and then deleting an image in the UI

const snapshotAfter = store.getSnapshot();
console.log('after', snapshotAfter.length);

before and after is distinguished by the absence of the shape that stored this assets, the assets remained in the store

How can we reproduce the bug?

Proposed Solution:

  • Develop a deletePageWithShapes method that efficiently removes the page along with all associated shapes and assets.
  • Ensure that when a shape linked to an image is deleted, the corresponding asset is also removed from the memory store.

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

Contact Details

[email protected]

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

c1DeepInside avatar Nov 27 '23 13:11 c1DeepInside

@ds300 This one is worth checking! Maybe we can do the same as we discussed for asset purging, i.e. purge shapes without pages when the document is first loaded locally for offline rooms or on the server for shared projects?

steveruizok avatar Nov 27 '23 15:11 steveruizok

Any kind of memory leaks make this library unstable on iOS devices, as iOS safari will just white screen of death if it decides it doesn't like what it sees

jpike88 avatar Jan 12 '24 05:01 jpike88

@steveruizok @ds300 any update on this or a workaround that can be suggested here?

eswarclynn avatar Apr 30 '24 10:04 eswarclynn