Export to GitHub

primefaces - issue #4848

Remove detached widgets after AJAX updates


Posted on Nov 8, 2012 by Grumpy Horse

Forum Post URL: http://forum.primefaces.org/viewtopic.php?f=3&t=25942

What steps will reproduce the problem? See the post for a complete example. (a netbeans project can be attached if desired)

What is the PrimeFaces version? 3.3.1, 3.4.1

Which JSF implementation with version are you using?(Mojarra or MyFaces) Mojarra

What is the version of your JSF implementation? 2.1.7

Which component libraries are you using in addition to PrimeFaces? primefaces-extensions

Which application server or servlet container are you using? JBoss 6.1

Comment #1

Posted on Nov 9, 2012 by Swift Rhino

Do you have a patch?

Comment #2

Posted on Nov 9, 2012 by Grumpy Horse

Hi Cagatay, I attached two patches based on today's trunk (3.5.-SNAPSHOT).

  • core.js.patch - contains the object to store the reference of a widget (quite like before, but simpler in handling later on) and the hook to invoke dispose() for invisible widgets
  • forms.js.patch - contains a demo of the dispose-implementation for the splitbutton-widget

The rest of the widgets should be touched in a similar fashion in order to close the leak. I'm willing to provide some more patches (as far as I'm able to understand the internals of a widget) if you approve the patches. But let's discuss this later. ;)

I'm looking forward to your reply.

Best regards, Dennis

Attachments

Comment #3

Posted on Nov 13, 2012 by Grumpy Horse

Hi there, I discovered a flaw which doesn't take care of the widgetVar-attribute. I posted a solution in the forum (http://forum.primefaces.org/viewtopic.php?f=3&t=25942&p=82478#p82478), but the the patch above does still work as a proof-of-concept.

A new version of the patch would include the handling for widgetVars as also fixes for "commandButton", "ajaxStatus" and "overlayPanel".

Regards

Comment #4

Posted on Nov 14, 2012 by Swift Rhino

(No comment was entered for this change.)

Comment #5

Posted on Nov 21, 2012 by Grumpy Horse

Hi, it was a busy week, but I finally managed to extend the patch.

i) it now covers contextmenu and because of the class hierarchy tiered- and normal menus also ii) widgets which are attached to non-existent targets are also cleared (like contextmenu iii) DOM-nodes of widgets which are attached directly at the document-root are also removed if they were related to targets which were removed in the update-node

Attachments

Comment #6

Posted on Dec 17, 2012 by Grumpy Horse

The previous patches are running smoothly in our system so far. Here is another patch for the autocomplete component.

Attachments

Comment #7

Posted on Dec 17, 2012 by Grumpy Horse

Patch for defaultCommand

Attachments

Comment #8

Posted on Nov 21, 2013 by Happy Rhino

Is there any plans for this to be patched into the near future.

Comment #9

Posted on Nov 28, 2013 by Swift Elephant

(No comment was entered for this change.)

Comment #10

Posted on Nov 30, 2013 by Swift Elephant

I just added a patch for core: http://code.google.com/p/primefaces/source/detail?r=10288 We now only need to overwrite isDetached and destroy in some of our widgets.

Comment #11

Posted on Nov 30, 2013 by Swift Elephant

@Dennis Is it REALLY required to remove events on elements that will be removed during AJAX update? I think that jQuery should handle this.

Please check the last post here: http://forum.primefaces.org/viewtopic.php?f=3&t=25942&start=10

Comment #12

Posted on Nov 30, 2013 by Grumpy Horse

Hi Thomas, it's been a long time ago I was being in touch with this issue and I'm currently not at my workplace to check my old example. But here are some quick points:

  • In reply to your question: As far as I remember there were some references of the bound functions after removing the widget from DOM using jQuery. But this could be related to the circumstance that they had not been bounded using jQuery's on() or that the GC of Chrome was not smart enough at this time. ;)

  • attached patch: I just had a quick look at your patch. Do I understand this correctly: This patch handles widget which have a the widgetVar-attribute set only? (The check for widgetVar in the BaseWidget).

  • I think another issue was, that anonymous functions prevented a widget to be removed from memory if multiple instances of this kind of widget were used on the same page. This was the cause for me to define a var for some functions and sometimes it was even necessary to create a namespace at binding time (see window.bind('resize....')) in order not to destroy all of them if only one widget is removed. I guess that should be done every time a handler is attached to the window, document or a form (see defaultCommand-patch or pf4848_patch_bundle above).

As you can see I need make myself familiar with this issue again, but I'm not able to access my sources before Monday.

How about open a chat/hangout over Facebook/Google+? Would be easier to clarify this issue rather than using this bugtracker as a chat-platform. =) (and we could also talk in German ;)) Just send a PM in the forum.

Best regards

Comment #13

Posted on Nov 30, 2013 by Swift Elephant

Hi Dennis,

thanks for your feedback. I know, it's already a year now. So sorry for my late response, too!

I really appreciate your help here, i'm not that familiar with browser memory analyzing :)

All our widgets has a widgetVar - defined or not defined. So it doesn't matter.

Yes, please! A chat is much easier!

Comment #14

Posted on Dec 2, 2013 by Helpful Lion

The new patch throw this exception "PF(...) is null", because the widget is destroyed.

this function: isDetached: function() { return document.getElementById(this.id); }

is returning the correct value? when the id exist isDetached returns a true value?

Comment #15

Posted on Dec 2, 2013 by Swift Elephant

i think it should be "!document.getElementById(this.id)"

Comment #16

Posted on Dec 2, 2013 by Helpful Lion

I think so, meanwhile I changed to "document.getElementById(this.id) === null" to test the new delay option.

Comment #17

Posted on Dec 8, 2013 by Swift Elephant

Implemented API and logic Now it's required to check each widget, if they can be removed from memory completely. If not, we must touch this widget and implemented a custom #destroy method.

Dennis will help me to find this widgets and fix them. I don't have time to check that much widgets...

Comment #18

Posted on Dec 8, 2013 by Swift Elephant

Working components: InputText CommandButton Dialog DataTable

Failing components: SplitButton

Comment #19

Posted on Dec 21, 2013 by Swift Rhino

(No comment was entered for this change.)

Status: Fixed

Labels:
Priority-Medium Type-NewFeature TargetVersion-5.0