PDA

View Full Version : Memory usage and destroying objects



brookd
5 Dec 2008, 1:52 PM
I am wondering, I have read that Ext will only clean up objects that are in the items array + listeners (is that right?). So lets say I have a class that extends panel,and in it I create 3 Ext.data.Store's.

What is best practice? Add a beforeDestroy() method on the class, and call destroy() on each component? Could I iterate through the object, and check the type of each object, and if its an ext class, call destroy? Should I add listeners on the stores, that listen for the panels destroy event and destroy them from there?

What about if I create a combobox, say, for an custom cell editor. If I create within my class using "this", will it be auto destroyed when the class is destroyed?

What is best practice in this regard? Will all instance variables created inside an extended class also be destroyed when the destroy method is called?

I wish there was a best practices guide to managing memory effectively with Ext.

Animal
6 Dec 2008, 1:24 AM
With Ext's "Template Method" pattern, a subclass "contributes" functionality at key phases of the class's lifecycle.

For example, onRender is where you would add elements to the DOM element repesenting a Component.

The equivalent Template Method at destroy time is onDestroy. This will be called whenever an instance of a Component is destyroyed.

Your subclass will provide an implementation of this, and if you have created resources which need to be cleared up (Ext has no way of knowing when to clear them up itself), then you call the superclass's onDestroy in your implementation to get the usual cleanup done, and then perform your own cleanup logic.

dolittle
6 Dec 2008, 1:46 AM
What kind of stuff do you need to destroy?
Everybody are moving to a one page app and it is very important.

Do I need to manually destroy a store, dataview, records...?
How do you destroy a store?

Animal
6 Dec 2008, 2:10 AM
You shouldn't need to, but there is a private destroy method of Store.

Nexcet
9 Dec 2008, 1:31 PM
I would definitely use xtype which is component configs to define objects (inside forms and such as an example). Instantiation objects get stored in memory where component configs render on fly.. yes?

brookd
10 Dec 2008, 8:30 AM
That is correct. Using xtype as opposed to 'new', creates and stores only an object (the config object). This is good practice for sure..