Quantcast
Viewing latest article 5
Browse Latest Browse All 13

Optimizing app with hundreds of views, any tips?

I have been working on an app which creates tables (tables + chairs) using views.

So, let's say I want to create a table with 4 chairs.

I have one view which acts as the table, 4 views for the 4 chairs, and a container to host the tables and chairs. So my views for one table is as follows:

Container
 - Table
 - Chair1
 - Chair2
 - Chair3
 - Chair4
Total: 6 views per table.

All those views except the container view have touchEnabled=false (I thought this might make the views less expensive).

Now, the problem I have encountered is that when I create 50 tables (50x6=300 views), the app responds very slowly (after they have been rendered).

I thought maybe there is a memory leak, so I created an interval to update a label every second with availableMemory. It shows between 0.033 - 0.020 kb. Since I don't have anything to compare it to, I created a new app with a window->view->label and the label is updated every second with available memory, it says 0.033.

Code used in both places: app with tables that lags and a clean app.

var win = Titanium.UI.createWindow({ 
    backgroundColor:'#fff'
});
 
var view = Ti.UI.createView({});
 
var availableMemory = Ti.UI.createLabel({
    text: (Ti.Platform.availableMemory/(1024)),
    width: 200
});
view.add(availableMemory);
 
setInterval(function(){
    availableMemory.text = (Ti.Platform.availableMemory/1024).toString();
}, 1500);
 
win.add(view);
win.open();
How is it possible that a clean app is using the 24mb of available memory when its blank?!

Also, any tips on how I can show a lot of views without it becoming unusable? What are some things I should avoid? PS: Removing the views is not an option.


Viewing latest article 5
Browse Latest Browse All 13

Trending Articles