View Full Version : [OPEN] Ext.data.Model.cache keeps records of destroyed stores

28 Nov 2012, 12:52 PM
Ext version tested:

Sencha Touch 2.1
Browser versions tested against:

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.
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:

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 // 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


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
Thanks for the report! I have opened a bug in our bug tracker.

29 Nov 2012, 2:16 AM
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,

15 Apr 2013, 12:05 AM
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).