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 happening while using registerModule/unregisterModule. #1506

Closed
skkart opened this Issue Feb 13, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@skkart
Copy link

skkart commented Feb 13, 2019

We are observing memory leak of Store._vm while using registerModule/unregisterModule.
On heap profiling we found that the oldVm instance is not getting garbage collected.

I have created an demo link to illustrate the above mentioned problem
jsFiddle link

Probable Solution:
De-reference the oldVm instance on the same function scope where its getting instantiated (i.e. resetStoreVM() )

The above can be achieved by adding following code inside resetStoreVM function.
oldVm.$destroy();
oldVm = null; // This is the missing code

function resetStoreVM (store, state, hot) {
    var oldVm = store._vm;

    ...
	...

    if (oldVm) {
      if (hot) {
        // dispatch changes in all subscribed watchers
        // to force getter re-evaluation for hot reloading.
        store._withCommit(function () {
          oldVm._data.$$state = null;
        });
      }

      // Existing Code
      Vue.nextTick(function () { return oldVm.$destroy(); });
       
      // The OldVm Object is still in heap even after destroy
      // Appropriate Code
      oldVm.$destroy(); 
      oldVm = null;
    }
  }

Attached google chrome (V 72.0.3626.96) heap snapshot and file.
heapsnapshot

Heap-20190213T172945.heapsnapshot.zip

@vue-bot

This comment has been minimized.

Copy link

vue-bot commented Feb 13, 2019

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!

@vue-bot vue-bot closed this Feb 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.