]> khamidou — GitHub mirrors - electron.git/commitdiff
Release resources in browser when renderer view is gonna unloaded.
authorCheng Zhao <zcbenz@gmail.com>
Wed, 1 May 2013 02:59:29 +0000 (10:59 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 1 May 2013 02:59:29 +0000 (10:59 +0800)
browser/atom/objects_registry.coffee
browser/atom/rpc_server.coffee
renderer/api/lib/remote.coffee

index fb886eb0e641bea3e0b989f605d19784f5fb76f7..f921eb64de814279b640050e3baf36f31b0b9cd7 100644 (file)
@@ -31,6 +31,10 @@ class ObjectsStore
     @stores[key] = new ObjectsStore unless @stores[key]?
     @stores[key]
 
+  @releaseForRenderView: (processId, routingId) ->
+    key = "#{processId}_#{routingId}"
+    delete @stores[key]
+
 # Objects in weak map will be not referenced (so we won't leak memory), and
 # every object created in browser will have a unique id in weak map.
 objectsWeakMap = new IDWeakMap
@@ -72,3 +76,6 @@ exports.getAllWindows = () ->
 
 exports.remove = (processId, routingId, storeId) ->
   ObjectsStore.forRenderView(processId, routingId).remove storeId
+
+exports.clear = (processId, routingId) ->
+  ObjectsStore.releaseForRenderView processId, routingId
index 8c8eed65e9b1b5b994c8089c7782e2c20f5db5f2..bbcc2f3cfa45c65a16f3e8b7017de14829cc60d0 100644 (file)
@@ -43,6 +43,9 @@ ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) ->
   catch e
     event.result = type: 'error', value: e.message
 
+ipc.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (event, processId, routingId) ->
+  objectsRegistry.clear processId, routingId
+
 ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) ->
   try
     windows = objectsRegistry.getAllWindows()
index 4b74be890c45f643abb0663e582a53e4986889d5..23f5c6bae0a439cf3b4f955f4cc8024cac8f4823 100644 (file)
@@ -53,6 +53,10 @@ metaToValue = (meta) ->
 
       ret
 
+# Release all resources of current render view when it's going to be unloaded.
+window.addEventListener 'unload', (event) ->
+  ipc.sendChannelSync 'ATOM_BROWSER_RELEASE_RENDER_VIEW'
+
 # Get remote module.
 exports.require = (module) ->
   meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module