PDA

View Full Version : Memory warnings and application crash



manvinder
6 Sep 2012, 6:01 PM
Hi all,

When I run my app on iPad the app crashes after giving memory warnings.

In the app I have to search a record in store. for this I am using filterBy() function. the search works fine 2-3 times and gives the result correctly. but after that keeping search continue I am started getting memory warning and application crashes.

Please help

suzuki1100nz
7 Sep 2012, 12:00 AM
Hi - Post your code please.

manvinder
7 Sep 2012, 1:31 AM
hi,

Thanks for quick response. here is code fragment

var categoryStore = Ext.create('Ext.data.Store', {
model: 'MyStore.model.Products',
proxy: {
type: 'ajax',
url : 'app/data/' + record.get('categoryId') +'.json' ,
reader: {
type: 'json',
rootProperty: 'items'
}
},
autoLoad: true
});

categoryStore.on('load', function() {
categoryStore.each(function(rec) {
(rec.products()).filter('productId', sProductId);
productRecord = (rec.products()).queryBy(function(record) {
if(record.get('productId') == sProductId) {
console.log('Matched Product Id: ' + record.get('productId'));
searchRecord = record;
return true;
}
});
});
if(searchRecord) {
productInfoStore = searchRecord;//used as store in selectFinish

if(searchRecord.get('productId') == "") {//product can not be added to cart
Ext.getCmp('addToCart').hide();
Ext.getCmp('updateCart').hide();
Ext.getCmp('productSizeList').hide();
}
else {
Ext.getCmp('addToCart').show();
Ext.getCmp('updateCart').hide();
Ext.getCmp('productSizeList').show();
}
Ext.getCmp('productInfo').getTpl().overwrite(Ext.getCmp('productInfo').element, searchRecord.data);
//Ext.getCmp('productDetailTitlebar').setTitle('Product Detail: #' + searchRecord.get('patternNumber'));
if(searchRecord.get('hResImgUrl')!="noImage"){
Ext.getCmp('productDetailImage').setHtml('<img src="' + searchRecord.get('bgImgUrl') + '">');
}else{
Ext.getCmp('productDetailImage').setHtml('<div class="product"><img src="' + searchRecord.get('bgImgUrl') + '"></div>');
}
console.log('SearchRecord: ' + searchRecord.get('patternNumber'));

var availableFinish = searchRecord.availableFinish();
var options =[];
availableFinish.each(function(record) {
options.push({text: record.get('text'), value: record.get('value')});
});
Ext.getCmp('selectFinish').setOptions(options);
if(Ext.getCmp('selectFinish').getStore().getAt(0).get('text') == '') {
Ext.getCmp('selectFinish').hide();
}
else {
Ext.getCmp('selectFinish').show();
}

Ext.getCmp('productSizeList').setStore(searchRecord.availableFinish().getAt(0).availableSizes());
if(Ext.getCmp('productSizeList').getStore().getCount() > 0) {
Ext.getCmp('productSizeList').select(0, true, false);
}

me.getHome().setActiveItem(me.listingDetail);
}
});

suzuki1100nz
7 Sep 2012, 4:28 PM
I would check image sizes and possible memory issues.
Also are you cleaning out the dom? Run your app in safari on the desktop or chrome and inspect the dom.
Make sure its not growing as you do searches.

This code block runs on the store load - does it only run once?

you can check number of dom elements with this code in the console - document.getElementsByTagName("*").length

A lot of getCmp() use which isnt ideal - if this class needs to know about a lot of components then set references on this class as the components are constructed. The you will have a reference to the components instead of having to search for them. References get set once during construction.

manvinder
11 Sep 2012, 11:16 PM
Thanks for your reply. It was realy helpfull.:)