Skip to content

Memory leak happening while using registerModule/unregisterModule. #1507

Closed
@skkart

Description

@skkart

Version

3.1.0

Reproduction link

https://jsfiddle.net/mrj8spu0/

Steps to reproduce

  1. Open the JSFiddle link mentioned as part of this issue.
  2. Check and record the heap memory in the browser on initial stage.
  3. Click on the "Register" button to dynamically register Module B 100 times
  4. Now we will see an increase in heap memory on account of registering module 100 times.
  5. Click on "Un-Register" button to dynamically un-register Module B 100 times
  6. Check the heap memory again, at this point will see an jump in memory usage on account of un-registering 100 module.

What is expected?

Heap memory generated on step 3 & 5 must be cleared after step 6. (Final stage)

What is actually happening?

Heap memory of the browser is not getting cleared.


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

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

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

Heap-20190213T220212.heaptimeline.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions