mardi 4 mars 2008

Component destruction

It was long ago that we see that we can't destroy a component.

We don't see real memory leaks but for event listening it is more important. It was very difficult to stop all listeners that we create in a component. But in a big RIA application, we were forced to manually handle persistence of a component which had disappeared a long time before (and continue to receive all events...).

Trunk version adds now a new inherited method in all components (method is present in the abstract component) which offer to disconnect all event listening in the component.

There was a difficulty for creating this method : disconnect a listening must be done with the good pointer of exactly the same function than where it was created. This function was not easily accessible at all. In most case, the pointer was lost.

There are two types of event listening in a components : Archetype events and DOM elements events.
For Archetype events it was much simple, we managed listening, so I added a storing of the function in order to use it for disconnecting.
For DOM elements events we didn't managed listening so I have created a new MethodBuilder which overload the "observe" method. It has now the same structure than Event.observe of Prototype but we store listening function and we are able to disconnect it on component destruction.

You must just remember using "this.observe" for DOM element listening in order to disconnect this listening too on destruction.

In the future, it can be interesting to study a more complete destruction which can be able to free some memory.

Using "this.observe" is a bit fastidious for the moment but we start reflection on an much easy way to configure DOM event listening (much easier than Prototype if it's possible!). You can follow this work on JIRA.