scratchfoundation / scratchfoundation/scratch-editor

Memory leak on disposing targets or load project

Open
#587 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Open DevTools, Shot a memory heap snapshot.
  2. Open a large project, like https://scratch.mit.edu/projects/613688710
  3. Shot again.
  4. Create a new project, shot again.

Screenshots

(Init -> Load an large project -> Create a new project)

Image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.