I’m starting to work with Sencha Touch 2 and I just wondered how does it (if even) handle resource cleanups.
In particular:
-
imagine we have a bunch of controllers which are triggered by url redirects. Will those Controller instances be cached or is Sencha creating fresh instances everytime that it needs to invoke a method on a controller
-
Same for views. Does sencha cache views or will it recreate them everytime it needs to render them again. When exactly are views destroyed (if they are)?
-
can I get control on how sencha handles those things?
To answer your questions,
Only one instance of each controller is created by Sencha. So, I really think you do not need to bother about the controller instances. Let Sencha handle that.
The cleanup should actually be done with the Views because the number of views and complexity of them are closely related to the performance.
Sencha doesn’t cleanup its resources specifically – the developer must take care of the DOM cleanup explicitly (apart from Javascript’s own garbage collection mechanism). So, the developer needs to decide when to create a view, whether to keep it in the DOM for future use or to destroy it as soon as its hidden. Let me give some examples:
A.
B.
So, these are some scenarios where the Views can be removed explicitly when needed. Below are some references which gives good idea about the memory optimization with Sencha:
a) Sencha Touch: Optimizing Memory Usage
b) http://www.slideshare.net/senchainc/optimizing-performance