Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when creating many decoration types and disposing them #7609

Closed
ArtemGovorov opened this issue Jun 13, 2016 · 9 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority verification-found Issue verification failed verified Verification succeeded
Milestone

Comments

@ArtemGovorov
Copy link
Contributor

ArtemGovorov commented Jun 13, 2016

  • VSCode Version: 1.2.0
  • OS Version: OSX

Now when it's possible to set the contentText for a decoration with this change, one may need to create quite a few transient decoration types to display/update the side content for certain code lines.

I tried to simulate my scenario and it looks like some resources are not cleared when disposing a decoration type.

Steps to Reproduce:

Here is the test code:

  let getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
  let decorationTypes = [];
  let editor = window.visibleTextEditors[0];
  setInterval(function () {
    decorationTypes.forEach(dt => {
      editor.setDecorations(dt, []);
      dt.dispose();
    });
    decorationTypes.length = 0;
    for (let i = 0; i < 1000; i++) {
      let dt = window.createTextEditorDecorationType({after: {contentText: getRandomInt(0, Number.MAX_SAFE_INTEGER)}});
      editor.setDecorations(dt, [new vscode.Range(i, 0, i, 1000)]);
      decorationTypes.push(dt);
    }
  }, 1);

The memory consumption grows rapidly and after a couple of minutes I get the process crash:

screen shot 2016-06-13 at 10 36 17 pm

Note that the issue can be reproduced with the current release version on VS Code (not only the insiders build), so it wasn't introduced by the change.

@sandy081 sandy081 added the bug Issue identified by VS Code Team member as probable bug label Jun 13, 2016
@sandy081 sandy081 added the important Issue identified as high-priority label Jun 13, 2016
@aeschli
Copy link
Contributor

aeschli commented Jun 13, 2016

Note that decoration types are kept until you call dispose on them. I will have a look, but it's clear you can't create too many of them.
With the latest change you don't need to create a decoration type for every attachment text, but can refine the type by defining before & after attachments on the decoration itself. These decoration are more expensive to be build (css rules need to be added) but are cleaned up as soon as not shown anymore.

@ArtemGovorov
Copy link
Contributor Author

Note that decoration types are kept until you call dispose on them.

I call dispose in the provided test code for all decoration types. There still must be something somewhere that is not cleaned up.

With the latest change you don't need to create a decoration type for every attachment text, but can refine the type by defining before & after attachments on the decoration itself.

Oh, it's awesome, I didn't realise that, thanks for noting it. It fits my scenario much better than creating a lot of decoration types.

@alexdima alexdima assigned alexdima and unassigned aeschli Jun 17, 2016
@alexdima
Copy link
Member

alexdima commented Jun 17, 2016

The refCount property is not initialized on DecorationTypeOptionsProvider, making provider.refCount++ turn it into NaN, making this code in removeDecorationType not succeed:

            provider.refCount--;
            if (provider.refCount <= 0) {
                delete this._decorationOptionProviders[key];
                provider.dispose();
                this.listCodeEditors().forEach((ed) => ed.removeDecorations(key));
            }

Spotted and fixed while merging #6553

@alexdima
Copy link
Member

Fixed while merging #6553 with 9e7b462

@alexdima alexdima added this to the June 2016 milestone Jun 17, 2016
@aeschli
Copy link
Contributor

aeschli commented Jun 17, 2016

Thanks @alexandrudima !

@isidorn isidorn added verified Verification succeeded and removed verified Verification succeeded labels Jul 4, 2016
@isidorn
Copy link
Contributor

isidorn commented Jul 4, 2016

Using the snippet user provided I can still crash VScode after 1 minute, not sure if that is expected (there is a timeout of 1ms, so it is really adding a bunch of decorations). Though I do not get an error in the console, just after running the extension whole vscode crashes.

Reopening so @alexandrudima can decide if this is expected or not

@isidorn isidorn reopened this Jul 4, 2016
@isidorn isidorn added the verification-found Issue verification failed label Jul 4, 2016
@alexdima
Copy link
Member

alexdima commented Jul 4, 2016

I have a fix in a09ee36

@jrieken jrieken added the candidate Issue identified as probable candidate for fixing in the next release label Jul 5, 2016
@jrieken jrieken self-assigned this Jul 5, 2016
@alexdima
Copy link
Member

alexdima commented Jul 5, 2016

@jrieken Pushed fix to release/1.3.0. The fix is to clear all data associated with a decoration type in the editor. Please verify that those members are always accessed in a safe way. The contract is that the decoration type will always be unique and once removed, it will never come back (the change has no other side effects except fixing the memory leak).

@alexdima alexdima closed this as completed Jul 5, 2016
@jrieken
Copy link
Member

jrieken commented Jul 5, 2016

Change looks good, works in scripts/code.sh. I will verify with the build

@jrieken jrieken added the verified Verification succeeded label Jul 5, 2016
@joaomoreno joaomoreno removed the candidate Issue identified as probable candidate for fixing in the next release label Jul 11, 2016
@joaomoreno joaomoreno removed this from the July Stable Recovery milestone Jul 11, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority verification-found Issue verification failed verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

7 participants