Garbage collection of Name objects

# Mike Samuel (17 years ago)

I was looking at strawman:names on Name objects, and was wondering whether garbage collection of name objects has been discussed.

I'm not a GC expert, so the below may be hopelessly naive, and I don't know whether this kind of thing is appropriate for a language spec, but I wanted to raise the issue because some cool things become possible if short lived namespaces don't leak memory when attached to long-lived objects.

My understanding is that existing ES3 interpreters consider an object reachable if it is any of the following (1) a value of a variable/actual/const from the scope chain of any executing or reachable function -- this includes the global object and any objects in with clauses (2) the value of a property of a reachable object (3) pinned in memory by a host object.

With Name objects, that has to change. A name object is additionally reachable if it is the key in an enumerable property, since a for(...in...) loop can always bring a Name object back into the scope chain of an executing function. If it is the key in a non-enumerable property, then there is no way that it can be brought back into scope.

Can reachability in the presence of Names be specified thus: An object is reachable if it is any of the following (1) a value of a variable/actual/const from the scope chain of any executing or reachable function (2) the value of a property of a reachable object (* where the key is a string or a reachable Name ) (3) pinned in memory by a host object (4) ( the Name key of an enumerable property *) ?

So if a Name were only used as a key of an unenumerable property, then it could be collected as could the properties. This would not break frozenness if Object freezing were defined in terms of visible mutations.