JavaScript WeakMap referenziert weiterhin gc'ed Objekte

Ich habe Probleme mit JavaScript-Schwachstellen, nachdem ich diesen Code in der Google Chrome-Entwicklerkonsole mit --js-flags = "- expose-gc" ausgeführt habe. Ich verstehe nicht, warum die Schwachstelle weiterhin einen Verweis auf ab if a enthält wird 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?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage