You found a bug! We've classified it as TOUCH-3763 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    28
    Vote Rating
    2
    natb is on a distinguished road

      1  

    Default Ext.data.Model.cache keeps records of destroyed stores

    Ext.data.Model.cache keeps records of destroyed stores


    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().

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

  3. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    28
    Vote Rating
    2
    natb is on a distinguished road

      0  

    Default Update documentation

    Update documentation


    Thanks, could you please also add some more details about useCache flag into the documentation. Namely: 1) the main intention of this flag: tracking changes of recors with the same id? how is it used with associations? etc.; 2) advantages/disadvantages of using it; 3) when is it safe to switch it off and so on.

    Thank you in advance,
    Regards

  4. #4
    Sencha User
    Join Date
    Dec 2011
    Posts
    156
    Vote Rating
    3
    coolfish is on a distinguished road

      0  

    Default


    This bug appears to be related to a problem I'm experiencing. If an object is deleted (removed from store, and erased) and then I attempt to recreate the same object (reload it from the server) I get exceptions originating from the cached object (it refers to associated data that is now undefined).

Thread Participants: 2