How often is garbage collected?
If I understand correctly, GC works like this:
MyClass.prototype.render = function(){
var largeArray = [];
for (var i = 0; i < 1000; i++) {
largeArray.push({
firstName: 'John',
lastName: 'Smith'
});
}
}
When called render()
, largeArray
marked for garbage collection, but not immediately collected.
I'm curious because I have a lockscreen widget for my phone. It is a browser that shows an HTML page on a locked screen. It works so that every time I load my lockscreen, the widget reloads.
The problem is that every fifth time I open the screen lock, the phone restarts in safe mode. It seems when I unlock the phone the widget browser is closed before garbage collection can run. Does this sound right?
Here's my widget. In the console, it gives the size of the main objects.
source to share
Refer this link , your problem is not garbage collector, I think your code has some kind of variables that are created and located in memory and never released, check out these links for js best practices
[1] Recommendations for using JavaScript
source to share