How to avoid memory leaks using angularjs-nvd3-directives

后端 未结 3 863
闹比i
闹比i 2021-02-04 08:43

I\'m working on an angularjs application using angularjs-nvd3-directives to render charts.

After a check with Chrome Developer Tools, I detected some memory leaks linked

3条回答
  •  长情又很酷
    2021-02-04 08:57

    You might forget to remove window resize listeners.

    angularApp.run(function($rootScope) {
      $rootScope.$on('$routeChangeStart', function(event, next, current) {
        if (typeof(current) !== 'undefined'){
            //destroy d3 stuff 
            window.nv.charts = {};
            window.nv.graphs = [];
            window.nv.logs = {};
    
            // and remove listeers for onresize. 
            window.onresize = null;
        }
      });
    }); 
    

    Also you can try removing whole svg element but it doesn't seem to be the best way.

提交回复
热议问题