Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Sencha Touch 2 cleanup resources

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?

like image 532
Christoph Avatar asked Aug 22 '12 11:08

Christoph


1 Answers

To answer your questions,

  1. 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.

  2. 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

like image 161
Swar Avatar answered Sep 29 '22 12:09

Swar