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.
Suppose on clicking a button, user opens an INFO popup which shows some information about the page. Once the user read the info, he closes the popup. Now, from a user perspective, there may be a very little chance that the user will re-open the popup. So, best will be if the popup gets removed from the DOM as soon as user closes it. Anyhow, if the user wants to re-open it, re-create the popup and show it.
B.
Similarly suppose user is in login page and signing in to the application. Users hardly go back to the login page while within the app. So, destroy the login View instance once its hidden.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With