[Bug]: Memory leak when deleting a page or image
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
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
@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?
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
@steveruizok @ds300 any update on this or a workaround that can be suggested here?