PDA

View Full Version : [DEFER] 3.2.0 Potential memory leak in Component mon() & mun()



ceberle
21 May 2010, 11:06 AM
If you call mon() with the same arguments multiple times, each call will add another listener object to the mons array, even though the listener is only registered with the Observable once.

For example:


...
doSearch: function(params) {
...
this.mon(this.store, "load", this.onSearchResults, this);
...
}
...


The first call to doSearch will add a "load" listener to the store, and add an item to the mons array. Subsequent calls won't cause another "load" listener to be added, but it does add another item to the mons array.

Calling mun() to remove a listener only removes the first instance found in the mons array.

Either the mon() code should check if it already exists in the mons array or it should call mun() before pushing another item into the mons array.

I think the typical usage scenario won't lead to memory leaks, as the calls to mon() would likely only happen once during initialization, and the entire mons array gets cleaned up when the Component is destroyed; however, there's still potential for problems.

--Chad Eberle
Web Application Architect

Jamie Avins
21 May 2010, 11:09 AM
Yes, we're looking to refactor the mon/mun code for the next minor release.