Is `undefined` garabage collectable?

/#!/JoePea joe at trusktr.io
Wed May 4 20:43:44 UTC 2016


For example, I have some code that uses a Map just to keep a collection of
things (the keys) but values are not important, so they are undefined, like
this:

```js
let something = {}
let otherThing = {}
let m = new Map

m.set(something)
m.set(
​otherThing​
)
```

where the values for those object keys are `undefined` since there's not
second arg to `m.set`. If I add the line

```js
m.clear()
```

and retain references to `something`, `otherThing`, and `m`, I know that
those objects won't be GCed. What about the `undefined` values? Are those
`undefined` values something that the GC has to collect? Or do `undefined`
values literally reference nothing, not needing to be collected?

Just wondering because I want to avoid GC while rendering animations at
60fps. I know I can prevent GC if I retain a value to some constant, as in

```js
let something = {}
let otherThing = {}
const foo = true
let m = new Map

m.set(something, foo)
m.set(
​otherThing​, foo
)

m.clear()
```

so then if I retain the reference to `foo` then there's no GC; I'm just
sticking things in and out of the Map, but I'm curious to know how
`undefined` is treated, because if that prevents GC, then the code can be
cleaner.

 - Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160504/71353570/attachment.html>


More information about the es-discuss mailing list