PDA

View Full Version : Does store need to be removed forcefully once the grid using it is destroyed?



netemp
28 Mar 2012, 6:18 AM
In our application, we are having various windows which contain grid and their respective stores. General code structure of a window we have is as following:



function showWin(){
var storeVar = //code for store
var gridVar = //code for grid with store as storeVar
var winVar = //code for window having grid as item
winVar.show();
}


This showWin() function is being called say on a button click which displays the window.

Now when this window is closed then it is destroyed along with its child item grid. But does this also destroy the store associated with the grid? I guess not.

Thus, if storeVar is not destroyed on closing of window (more precisely on destruction of grid) then should this be forcefully removed in order to reduce the extra baggage (as a new copy gets created everytime the function is called) from the memory? If yes, how?

Thanks for any help in advance.

PS: We are using ExtJs ver 4.0.7

mitchellsimoens
28 Mar 2012, 8:42 AM
By default the grid will destroy the store and the garbage collector will come by and clean things up. If the store is registered with the StoreManager then the instance will stick around.

netemp
28 Mar 2012, 9:47 AM
Thanks for the reply mitchellsimoens.

By quoting:


If the store is registered with the StoreManager then the instance will stick around.

Are you suggesting that if we have used storeId at the store, only in that case the instance will stick around? But is every store not by default registered with the Store Manager as soon as its created?

mitchellsimoens
28 Mar 2012, 9:54 AM
The store is not registered unless you have storeId specified.

netemp
28 Mar 2012, 9:58 AM
The store is not registered unless you have storeId specified.


Great. Thanks.


Thus, from your this reply and the one posted above by you earlier, I can conclude that as per the old garbage collection principle, as soon as all the references to the store die, the store also is deleted by the garbage collector.


But if in the code structure shared above in the question, if we have one more variable menuVar as following:




function showWin(){
var menuVar = //code for menu to be displayed as context menu at grid
var storeVar = //code for store
var gridVar = //code for grid with store as storeVar and context menu as menuVar
var winVar = //code for window having grid as item
winVar.show();
}



Then once the grid is destroyed, will the menu also be destroyed (using the same principle of Garbage Collection)? Or will it have to be explicitly destroyed?


I guess we shall have to destroy the menu explicitly (as also shared by Jesus Garcia in his book ExtJs in Action while talking about grids), but then why this difference between menu and store variables?


Could you please guide.


Thanks for the time so far Mitchell.

netemp
28 Mar 2012, 11:36 PM
Any thoughts on this anyone?