Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4080

DataBinder.removeBinding _beanSameNodes memleak

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: 6.5.4
    • Fix Version/s: None
    • Component/s: Databind

      Description

      When removing a binding set in org.zkoss.zkplus.databind.DataBinder and derived classes by calling removeBinding(..), the respective BindingNode is not removed from _beanSameNodes, resulting in references to components (which may have been detached already) hanging in memory, without any option to clean this up (except hacking oneself into the private field using reflection, which I would consider very dirty). Ultimately, an application can crash by running out of memory.

      Proposed fix:
      public void removeBinding(Component comp, String attr) {
      Binding binding = super.getBinding(comp, attr); // we need this for cleanup
      super.removeBinding(comp, attr);

      if (binding != null) {
      // clean any leaks within _beanSameNodes if required
      if (_beanSameNodes != null) {
      for (Iterator<Set<Object>> it = _beanSameNodes.values().iterator(); it.hasNext() {
      Set<Object> value = it.next();
      if (value != null) {
      for (Iterator<Object> it1 = value.iterator(); it1.hasNext() {
      Object entry = it1.next();
      if (entry instanceof BindingNode)

      { cleanBindingNode((BindingNode) entry, binding); }

      }
      }
      }
      }
      }
      }

      /package/ static void cleanBindingNode(BindingNode bindingNode, Binding binding) {
      LinkedHashSet<Binding> bindings = bindingNode.getBindings();
      bindings.remove(binding);

      Collection<BindingNode> kidNodes = bindingNode.getKidNodes();
      for (Iterator<BindingNode> it = kidNodes.iterator(); it.hasNext()

      { cleanBindingNode(it.next(), binding); }

      }

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            chemFelix chemFelix
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: