-3

Please find Chtml code segment below:

<span class="GreyText"> 
  <!-- ko if:  vm.Name() == "CHANGE"?true:false -->
    <div style="color: Red; font: bold" data-bind="text : vm.Name">
    </div>
  <!-- /ko-->
</span>

I am using Knockout 2.0.3 plugin. Detach Nodes is caused by Ko_withIfBindingData. Please guide me on the same.

How to clear Detach Nodes caused by Ko_withIfBindingData

  • 1
    What is your question exactly? – Hans Roerdinkholder Oct 08 '14 at 09:05
  • How to clear Detach Nodes caused by Ko_withIfBindingData – Abhi Mukherjee Oct 08 '14 at 10:01
  • The way to clear detached nodes is to make sure no code holds a reference to them, preventing the browser from garbage collecting them. Having said that, the code you posted does not seem to be the problem. It's probably caused somewhere else in your code base. – Hans Roerdinkholder Oct 08 '14 at 10:12
  • This section of code over using Knockout plugin causing . setknockout-2.3.0.js:59 function (b, c, e) { if (e !== q || a.a.f.pa(b, !1) !== q) a.a.f.pa(b, !0)[c] = e } – Abhi Mukherjee Oct 08 '14 at 10:20
  • Without the if-block, there will be no nodes that are removed from the DOM and can end up detached. So indeed there will be no detached nodes. This does not necessarily mean that the leak is caused by the same line of code. If some part of your viewmodel references the DOM nodes for example, you could also create the leak there. Memory leaks are not trivial to detect. If you can reproduce this leak in a very simple scenario that does nothing else than the code you just posted, then you must be right. But I doubt you will still have detached nodes if you removed the rest of your code. – Hans Roerdinkholder Oct 08 '14 at 11:37
  • Hans Thanks for your Support . I will try to create a small POC with this If binding and also with out If binding and check if there is any Memory Leak . But For Now I have resolved this issue just replacing – Abhi Mukherjee Oct 08 '14 at 12:37
  • also why the ? true:false... wouldn't that happen without that? – Michael Crook Oct 08 '14 at 21:32

1 Answers1

0

The if binding will always result in detached nodes. That's because it saves a copy of the element contents as a template for later updates.

If you don't want this behavior, the visible binding might work for you.

Michael Best
  • 16,623
  • 1
  • 37
  • 70