Talk:Core JavaScript 1.5 Reference:Operators:Special Operators:delete Operator
From MDC
Is the delete objectName syntax in the ECMAScript specification, or is it a proprietary extension? The spec has this under the delete operator:
- Evaluate UnaryExpression.
- If Type(Result(1)) is not Reference, return true.
- Call GetBase(Result(1)).
- Call GetPropertyName(Result(1)).
- Call the Delete method on Result(3), providing Result(4) as the property name to delete.
- Return Result(5).
Maybe the scope (or rather the activation object or whatever it's called) would implicitly be the base of objectName and objectName is removed from the scope? Does the spec allow this?
More importantly, does using delete in this way actually directly free memory? Reference is ambiguous here and I'm not familiar with Spidermonkey's internal workings.
--Maian 09:32, 6 September 2005 (PDT)
- After looking at the spec, I can say without a doubt that this is allowed in ECMAScript, and not a JS extension. Identifiers and member accessors (obj.prop or obj['prop']) all return an internal type called "Reference" which is basically tuple comprised of the base object and the property. In the case of
delete identifier,identifierevaluates to a Reference, and the base object of this Reference is the "variable object" which is either the global object or the activation object (see chapter 10). The spec doesn't mention anything about garbage collection (or memory for that matter), so whether memory is freed in a delete statement depends entirely on the implementation. In any case, whether the memory is freed immediately shouldn't concern a JS author. --Maian 22:25, 10 November 2005 (PST)