cloudflarearchive / backgrid

Finally, an easily stylable semantic HTML data grid widget with a Javascript API that doesn't suck.
http://backgridjs.com
MIT License
2.01k stars 325 forks source link

ClientSideFilter .shadowCollection instance doesn't stopListening() on view.remove() #666

Open myklemykle opened 7 years ago

myklemykle commented 7 years ago

Hi,

I've discovered a memory leak in one of the Backgrid views in our app. The view creates a ClientSideFilter instance at .filter, and that clientSideFilter instance creates its own instance (at .shadowCollection) of the collection we hand it. In our case, we hand it a collection that listens to events on other objects.

We call remove() on our view when we're done with it, which frees the view and the ClientSideFilter instance, but not its .shadowCollection.

I can override remove() on our view to add a call this.filter.shadowCollection.stopListening(), which allows the collection to be dereferenced and fixes the leak.

Is that the right way to do it? It would be ideal if Backgrid's own remove() method would take care of that. Or is there some other API for deactivating/destroying a ClientSideFilter instance?