-
28 Nov 2012 12:52 PM #1
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
- Safari 5.1
- 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.
- 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.
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().
-
28 Nov 2012 7:50 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Thanks for the report! I have opened a bug in our bug tracker.
-
29 Nov 2012 2:16 AM #3
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
-
15 Apr 2013 12:05 AM #4
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).
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.


Reply With Quote