scratchfoundation / scratchfoundation/scratch-editor
Memory leak on disposing targets or load project
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 281
- Forks
- 276
- Avg merge
- 7d 8h
- Merged PRs (30d)
- 6
Description
Expected Behavior
The target's data should be clear when it get disposed.
Actual Behavior
Memory leak happens on both disposing targets or load project.
Steps to Reproduce
- Open DevTools, Shot a memory heap snapshot.
- Open a large project, like https://scratch.mit.edu/projects/613688710
- Shot again.
- Create a new project, shot again.
Screenshots
(Init -> Load an large project -> Create a new project)
The Cause
1. _StackFrameFreeList never get clear
_StackFrame holds target, and _StackFrameFreeList will recycle the disposed stack frames. but it never get clear.
A verified fix here: https://github.com/Clipteam/clipcc/pull/237
2. Previous target's skins won't get disposed
This problem has been addressed before (an issue in old scratch-gui repo). A workaround can be considered:
if (this.renderer && '_allSkins' in this.renderer) {
this.renderer._allSkins.forEach(skin => {
this.renderer!.destroySkin(skin._id);
});
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the leak with DevTools heap snapshots by loading the large project, then creating a new project. Trace disposal of _StackFrame objects and the _StackFrameFreeList, then inspect previous targets' renderer._allSkins and destroySkin handling; done means target data and skins no longer remain after disposal or project load.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100