How to unload objects from memory in EmberJS?

I have a controller that contains an array containing objects. Whenever I want to reload this array, I use controller.set('messages', []); .

In my browser, this works fine and does not cause the browser to crash. However, on the iPad, the application crashes after a few minutes. In my debug log, I see a memory warning. I assume that the objects remain in memory, which over time causes the application to crash. (I read somewhere that Safari on iPad has a 10 MB memory limit for javascript object, etc.)

Is this the right way to clear data from an array and remove all references to this object, so that it could be garbage collection by the system?

+4
source share
2 answers

I assume that you are encountering some relationships that are not deleted and therefore a memory issue. You can try one of the built-in Array methods, such as clear , this can do the right job.

For instance:

 controller.get('messages').clear(); 

Thus, the array will be reused.

Please let me know if this helps.

+2
source

You can call the destroy method on an Ember object.

Example:

 var messages = controller.get('messages'); messages.forEach(function(message) { message.destroy(); }); messages.clear(); 
+1
source

Source: https://habr.com/ru/post/1489530/


All Articles