I am facing a scenario where I am fetching JSON data from a backend and then rendering it using a template that contains several ng-show
directives.
<div>
<span ng-show="config.displayMode == 'A'" class="ng-binding">${A}</span>
<span ng-show="config.displayMode == 'B'" class="ng-binding">${B}</span>
<span ng-show="config.displayMode == 'C'" class="ng-binding">${C}</span>
</div>
Upon receiving new data, the template removes the existing elements and renders new ones.
Although this process works correctly and efficiently, I have observed through the Batarang performance tool that watches are being leaked every time elements are removed. As this page remains open for extended periods, the memory usage and digest time gradually increase, which is something I want to prevent.
EDIT The elements are removed using the .empty()
function of jQuery.
As requested, I have created a plunkr. The example is simple, adding an element with an ng-show
every time something is typed in a box. If the box is cleared, the ng-show
elements are deleted. By using Batarang, you can see that watches persist on the performance tab.
MY Question How can I clear the watches created by an ng-show
directive?