PDA

View Full Version : Destroying Multiple Stores at Once per View



ihutchcraft
28 Apr 2014, 10:24 AM
I'm currently working on a site that requires stores to be destroyed after leaving a page, then the stores are recreated when the page is accessed again. It is currently working with no issues using the code below, however, many views load multiple stores. I was looking for a way to destroy all recreated stores in a single destroy instead of continuously calling destroyStore and setting the store to null for every store that's loaded.


onHide: function() {
this.store.destroyStore();
this.store = null;

Ext.destroy(this.panel);
this.panel = null;

this.active = false;
},

I've done quite a bit of research but haven't found many ways. I'd considered looping over the stores, but couldn't come up with a way of differentiating the ones that need to be destroyed from the one's that do not need to be destroyed other than creating an array. But creating an array listing the stores that should not be destroyed seemed just as tedious as destroying each store individually.

Also, 'this' is the controller in case that's relevant.

Thanks for any insight you can give me.

skirtle
29 Apr 2014, 3:20 AM
I'm not sure this answers your question, but it's all the relevant information I can think of for this topic.

In recent version of ExtJS the method Ext.destroy can be passed a store and will call destroyStore. Check the source for your version to see whether it behaves this way.

The method Ext.destroyMembers is a quick way to destroy and null members of an object. However, it relies on Ext.destroy so it'll only help for stores if you're on a suitably recent version.

Stores have a flag set called autoDestroy. That flag is used to mark stores that are bound to a single component and that should be destroyed when that component is destroyed. The logic for this is in Ext.util.Bindable but it will only handle the single bound store for the component.

If nothing is referencing a store then it should be eligible for browser garbage collection without destroying it. However, I wouldn't advise going down this route as it is very easy for a store to leak and it can be expensive if it does. For example, each model in the store references the store so it only need a single model to be referenced to keep all the other records alive.

In the kind of scenario you're describing I would usually expect the components (by which I mean your subclasses) to be responsible for creating and destroying their own stores rather than trying to manage them all from the controller.

ihutchcraft
29 Apr 2014, 4:14 AM
Thanks. Ext.destroyMembers was enough to clean up some of the code so we weren't constantly setting the stores to null. I'm going to go through and change controllers and test it out today and make sure it's working consistently, but initial testing seems promising.

I just wanted to add that Ext.destroyMembers also worked for destroying the panels and stopped me from having to set the panel to null. This easily cut the function in half and seems to work better.

thanks

I appreciate the quick reply.