Reputation: 1421
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:
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)
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?
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)
Upvotes: 3
Views: 158
Reputation: 3036
I think you need to implement angular-websocket based approach, similar to Trello, whereby after a certain amount of time you ask the user to update their page to receive new updates to the system or to refresh if their socket connection has timed out? Depending on your setup you may find this tutorial useful: Writing an AngularJS App with Socket.IO.
Read the last update of accepted answer of your referred question.
Upvotes: 0
Reputation: 1636
Interesting, it seems like the loginController
isn't being cleared from memory. You may have to try triggering $destroy()
yourself to clear that controller. This assumes that it is being loaded multiple times.
Another few resources that may help: blog post about $destroy()
somewhat similar github issue
Upvotes: 1