The
If the property is an object reference, the
It can be useful to delete references to an object if you are finished with them, because this gives the garbage collector more information about what is able to be reclaimed. If references remain to a large object, this can cause it to be unreclaimed - even if the rest of your program doesn't actually use that object.
delete command has no effect on regular variables, only properties. After the delete command the property doesn't have the value null, it doesn't exist at all.If the property is an object reference, the
delete command deletes the property then the delete operator deletes only a reference, never an object itself.
If it did delete the object itself, other remaining references would be
dangling, like a C++ delete. (And accessing one of them would cause a
crash. To make them all turn null would mean having extra work when
deleting or extra memory for each object.)
Since Javascript is garbage collected, you don't need to delete
objects themselves - they will be removed when there is no way to refer
to them anymore. It can be useful to delete references to an object if you are finished with them, because this gives the garbage collector more information about what is able to be reclaimed. If references remain to a large object, this can cause it to be unreclaimed - even if the rest of your program doesn't actually use that object.
No comments:
Post a Comment