0 Replies Latest reply on Jul 6, 2012 2:05 PM by Christian Peter

    RF 3.3.3 Fighting (Browser) Memory-leaks by creating custom "cleaners"b

    Christian Peter Expert



      I'm currently facing some memory issues - mostly noticable with the firefox browser (version 13.x)  but also in IE and chrome (but there not so grave).


      These issues arise if a user stays quite a while on the same page and switches tabs and doing so causes rerendering of many components. We've added some jQuery-UI javascript libraries and I was aware that there could be some memory trouble but never thought about it again. Until some customers of mine complained about memory trouble like crashing or very slow browsers.


      So I tried to narrow it down and took measurements with the google chrome developer tool (timeline and heap snapshotting)....


      Simple rerendering of plain jsf 1.2 and most of the rf 3.3.3 components is no problem at all. The DOM Node Count increases and also the number of event listeners, but the garbage collection is good enough to clean it up. So no memory leak here.

      (h:outputText, h:inputText, h:inputTextarea, h:selectOneMenu.... rich:dataTable...)


      But then I tried the same approach with a rich:tree (and rich:recursiveTreeNodesAdaptor), rich:editor, rich:suggestionBox and rich:extendedDataTable: after rerendering there seem to be a increased number of DOM nodes and Eventlisteners which the garbage collection could not clean up.



      I'm also using a jQuery UI Multiselect which leaves a lot of "crap" even after properly destroying it.




      To solve this, I tried this:


      <a4j:queue onbeforedomupdate="cleanup(request.getResponseText());" />


      so every time an ajax-request is almost done, I parse the responseText and look for the list of IDs do become rerendered. For every ID I look up the component in the DOM and try to remove all attached eventlisterns and for all children. I also call the proper "destroy" functions of the multiselect, inputspinner and the datepicker here.


      This help, ..... a bit. It reduces the number of not removed eventlisteners by some factor.



      But this is not enough....



      So I looked into richfaces / a4j clientside javascript - in particular the "updatePagePart" functions. I found Richfaces.memory.


      In Richfaces.memory you can attach new "cleaner" listener which  will be called then the rerendering on the client begins.


      Is there some manual / documentation for this approach?


      I only found a jquery and a prototype "cleaner".


      I'll try to build an own cleaner which hopefully will cleanup the components created by jquery ui libraries...