Are Stores created in the initComponent function memory leaks once the component is destroyed or will these stores be garbage collected?

自古美人都是妖i 提交于 2020-05-15 08:08:49

问题


This is a question that surged from this other one:

Best practice to have the same view and store multiple times in ExtJS 4

So in a scenario where stores are created in the initComponent function of a grid.

Should I override onDestroy of the grid to also destroy the store ?

Or these stores would be garbage collected because simply there are no references to them?


回答1:


  1. No, the store will still exist after destroying the Grid
  2. No, you will not need to override the destroy method of the grid

You can force the store to destroy itself by setting it's autoDestroy flag to true API-Link

autoDestroy : Boolean

When a Store is used by only one DataView, and should only exist for the lifetime of that view, then configure the autoDestroy flag as true. This causes the destruction of the view to trigger the destruction of its Store.

Defaults to: false

See this working demo for the effect of autoDestroy on a store that is used by a grid (close the grids in the demo)

Additional info:

  1. Always use a storeId
  2. Use the StoreManager to lookup the existence of a store


来源:https://stackoverflow.com/questions/27368951/are-stores-created-in-the-initcomponent-function-memory-leaks-once-the-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!