Ng-if causing memory leak in angular js! Picture :https://www.mediafire.com/?ojoc55ccnyqlxyb
My app have two page
first page is homepage to show a input to search
second page is empy page to release memory .
How did I detected leak?
Run my app from link : http://www.mediafire.com/download/y5f6f326f3zo0ch/LeakProject_-_Copy.7z
use chrome in anonymus mode , F12 -> Profile -> Record Heap Allocation.
You click on homepage after that click on emptypage and repeat more time , result is no any leak.
But if you type any thing to seach , after that you go to emptypage to release memory . you will get leak.
I found that , when go to empty page ,scope of ovNgListBox in homepage will destroy . I think that value of scope.textSearch will change to undefined and $scope.$watch in ng-if of angualr.js will execute to destroy scope. But something is vice versa: Although scope of html
<ov-ng-list-box class="ng-isolate-scope"><div ng-init="showFilter=true" class="pull-right">
is destroyed.
but scope of
<input type="text" ng-model="textSearch" ng-if="showFilter" placeholder="please type here to search..." class="search ng-scope ng-pristine ng-valid">
is not destroyed . why why?
even if you to change value of scope.showFilter to false then $scope.$watch of in-if not called.
snippet code:
// templateleak.html <br/>
<div class="pull-right" ng-init="showFilter=true" >
<input type="text" class="search" placeholder="please type here to search..." ng-if="showFilter" ng-model="textSearch"/>
</div>
// my directive
app.directive('ovNgListBox', [function () {
return {
restrict: 'AE',
scope: {},
templateUrl: 'views/template/templateLeak.html',
controller: ['$scope',function(scope){
console.log("Im in link of directive");
scope.textSearch='';
scope.search = function(){};
scope.$on('$destroy', function(){
scope.showFilter=false;
});
}]
};
}])
//angular.js
var ngIfDirective = ['$animate', function($animate) {
return {
transclude: 'element',
priority: 600,
terminal: true,
restrict: 'A',
$$tlb: true,
link: function ($scope, $element, $attr, ctrl, $transclude) {
var block, childScope, previousElements;
$scope.$watch($attr.ngIf, function ngIfWatchAction(value) {
if (toBoolean(value)) {
if (!childScope) {
//