anam
anam

Reputation: 3913

Destroy Object completely

I am working on angularjs $modal. i am storing values in controller as below,

 if($scope.mediacontent){
 delete $scope.mediacontent;}
 $scope.mediacontent[$scope.slider_url] =media_data;
 $scope.mediacontent[$scope.slider_url][img_no].active=true; 

Now when next time $modal is opened I want to to destroy media content Object but with delete Object is not destroyed Completely.

How to destroy delete $scope.mediacontent Object Completely.

Upvotes: 0

Views: 236

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074495

(I'm assuming the syntax and other errors that JAAulde pointed out aren't really in your code, or that you've fixed it.)

but with delete Object is not destroyed Completely...

delete doesn't release objects; it removes properties. The object will be eligible for garbage collection if the property you're removing is the only reference to the object. When and how the actual garbage collection occurs is up to the JavaScript engine (it's unlikely to happen immediately). If you have other references to that object, then deleting the property won't make it eligible for GC (because of the other references to it).

But if you're about to assign a new value to the property, there's no reason for delete; assigning a new value also releases the reference to the previous object, making it eligible for GC (assuming nothing else has a reference to it).

E.g., this code will completely release the old object (unless something else has a reference to it):

$scope.mediacontent = {};
$scope.mediacontent[$scope.slider_url] = media_data;
$scope.mediacontent[$scope.slider_url][img_no].active = true; 

...because the first line of that replaces the reference to the old object with a reference to a newly-created one.

Upvotes: 3

Related Questions