REQUIRED INFORMATION
Ext version tested:
  • Sencha Touch 2.1
Browser versions tested against:
  • Safari 5.1
Description:
  • By default Ext.data.Model has useCache=true.
  • Each record of a store configured with such model is added to the Ext.data.Model.cache that seems to be needed for associations.
  • The problem is that store.destroy doesn't clear Ext.data.Model.cache. So the cache keeps a reference to each record, each record in its turn keeps reference to its store, so that memory doesn't get released.
Steps to reproduce the problem:
  • Define a Model with default configuration.
  • Create a Store with that Model and load some data to it.
  • Call Store.destroy() -> the store is marked as destroyed, store's cache is cleared, but models' cache still keeps all records of the store.
Test Case:
Code:
Ext.define('User', {    extend: 'Ext.data.Model',
    config: {
        fields: [
            {name: 'firstName', type: 'string'},
            {name: 'lastName',  type: 'string'}
        ]
    }
});




var data = [
        {firstName: 'Ed',    lastName: 'Spencer'},
        {firstName: 'Tommy', lastName: 'Maintz'},
        {firstName: 'Aaron', lastName: 'Conran'},
        {firstName: 'Jamie', lastName: 'Avins'}
    ];
    
var store1 = Ext.create('Ext.data.Store', {
    model: 'User', 
    storeId: 'test-store-1',
    data : data
});


Ext.StoreManager.map // test-store-1
Ext.data.Model.cache // user-ext-record-...


store1.destroy()


store1 // isDestroyed = true, OK
Ext.StoreManager.map // no test-store-1 reference, OK
Ext.data.Model.cache // BUG: all records still there, user-ext-record-..., with reference to test-store-1 each

Workaround:
  • To configure model's useCache=false (not always acceptable) or to call store.removeAll(true) before calling store.destroy().