I have audio player application implemented in AngularJS, but it consumes large amount of RAM. The sequence of actions I'm doing is the following:
- route to login page
- login then go to the next page
- logout
- repeat steps from 1 to 3 several times
The surprise is that the memory for the first step is 38 MB, then it increase to be 211 MB after the second step, after the third step it's 249 MB and so on, so it's accumulative and no memory is being freed after any of ng-view changes
Here it is sample of my code:
index.html page
<html ng-app="myApp">
<head><!-- application dependencies (js and css files) --></head>
<body>
<div ng-view></div>
</body>
</html>
app.js file
var app = angular.module('myApp', ['ngRoute']);
app.config(['$routeProvider', '$locationProvider', '$httpProvider',
function ($routeProvider, $locationProvider, $httpProvider) {
$routeProvider.when('/login', {
templateUrl: 'login.html',
controller: 'loginController'
});
$routeProvider.when('/', {
templateUrl: 'home.html',
resolve:{/** resolve function for login checking */}
controller: 'homeController'
});
}]);
I tried the solution of cleaning $templateCache as cleared in this question, but it can't be a solution in my case as I tried it and the problem not in the template itself, but something wrong with DOM and Controller data
How can I handle this memory issue, so when I change the view in ng-view It won't consume all this memory (as it's not the template size)
Update 1:
I switch between views when login or logout using $location.path('/route') after resolving the data of login and after checking the server's response after logout, so could it be the problem?
Update 2:
I created a plunker that simulate the increase of memory when switching views too much (of course it's not the actual numbers as it's a simulation)