]> khamidou — GitHub mirrors - electron.git/commitdiff
Erase window from weak map immediately after it's destroyed.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 20 May 2013 06:55:46 +0000 (14:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 20 May 2013 06:55:46 +0000 (14:55 +0800)
Otherwise it could happend that developers accessed the window after
it's destroyed but before it's GCed.

browser/atom/objects_registry.coffee

index 3dcdd58135d46cacc2544039e099217ca7dd52dc..ccd2a9135091af049036bf8e04b7f3f530bc61bf 100644 (file)
@@ -55,7 +55,10 @@ process.on 'ATOM_BROWSER_INTERNAL_NEW', (obj) ->
   objectsWeakMap.add obj
 
   # Also remember all windows.
-  windowsWeakMap.add obj if obj.constructor is BrowserWindow
+  if obj.constructor is BrowserWindow
+    id = windowsWeakMap.add obj
+    obj.on 'destroyed', ->
+      windowsWeakMap.remove id
 
 exports.add = (processId, routingId, obj) ->
   # Some native objects may already been added to objectsWeakMap, be care not