Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory: Widgets with "target" or "trigger" leak #11700

Open
11 tasks
melloware opened this issue Mar 29, 2024 · 1 comment
Open
11 tasks

Memory: Widgets with "target" or "trigger" leak #11700

melloware opened this issue Mar 29, 2024 · 1 comment
Assignees
Labels
⚡ performance Performance related issue or enhancement

Comments

@melloware
Copy link
Member

melloware commented Mar 29, 2024

This was a major cause of the leak at my client. Any element that has a trigger/target element should remove its widget when its target/trigger is removed from the DOM.

  • TieredMenu (any kind that uses trigger)
  • Sticky (target)
  • OverlayPanel (target)
  • BlockUI (target)
  • KeyFilter (target)
  • Spotlight (target)
  • Tooltip (target)
  • Resizable (jqTarget)
  • DragDrop (jqTarget)
  • ContextMenu (jqTarget)
  • ColumnToggler (trigger and its datatable)

Reproducer

This is easy to replicate using the showcase:

  1. Navigate to Sticky example: https://www.primefaces.org/showcase/ui/misc/sticky.xhtml
  2. Open F12 console and lets remove the Toolbar from the DOM with $('#tb').remove();
  3. Now take a Memory Dump and you will see the Toolbar was removed from DOM but the p:sticky still has a JS reference to it in its target property which causes the garbage collector to never collect it.
  4. Run PrimeFaces.destoyDetachedWidgets()

The 6 buttons, all their DIVS and everything inside the toolbar is now being held in memory as "Detached DOM" elements.

image

@melloware melloware added the ⚡ performance Performance related issue or enhancement label Mar 29, 2024
@melloware melloware self-assigned this Mar 29, 2024
@melloware
Copy link
Member Author

This is just a workaround not the final solution but this fixes it for all components.

$(document).ready(function () {
  for (key in PrimeFaces.widgets) {
    let widget = PrimeFaces.widgets[key];
    if (widget && widget.target instanceof jQuery) {
      widget.target.off("remove.widget").on("remove.widget", function () {
        PrimeFaces.detachedWidgets.push(widget.widgetVar);
      });
    }

    if (widget && widget.trigger instanceof jQuery) {
      widget.trigger.off("remove.widget").on("remove.widget", function () {
        PrimeFaces.detachedWidgets.push(widget.widgetVar);
      });
    }
  }
});

melloware added a commit to melloware/primefaces that referenced this issue Mar 29, 2024
melloware added a commit to melloware/primefaces that referenced this issue Mar 29, 2024
melloware added a commit to melloware/primefaces that referenced this issue Mar 29, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 1, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 3, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 4, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 4, 2024
@melloware melloware added this to the 13.0.8 milestone Apr 4, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 5, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 5, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 7, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
melloware added a commit to melloware/primefaces that referenced this issue Apr 10, 2024
@melloware melloware removed this from the 13.0.8 milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ performance Performance related issue or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant