Garbage collection - JavaScript WeakMap keep referencing gc39ed objects

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I am experiencing with JavaScript weakmaps, after trying this code in google chrome developer console, running with --js-flags="--expose-gc", I don t understand why the weakmap keep having a reference to a.b if a is gc ed.

var a = {listener: function(){ console.log( A ) }}
a.b = {listener: function(){ console.log( B ) }}

var map = new WeakMap()

map.set(a.b, [])
map.set(a, [a.b.listener])

console.log(map) // has both a and a.b

gc()
console.log(map) // still have both a and a.b

a = undefined
gc()
console.log(map) // only have a.b: why does still have a reference to a.b? Should nt be erased?

Answers

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/38203446/javascript-weakmap-keep-referencing-gced-objects

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils