From: Cheng Zhao Date: Wed, 1 May 2013 02:59:29 +0000 (+0800) Subject: Release resources in browser when renderer view is gonna unloaded. X-Git-Tag: v0.1.0~228 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=31d6be0e632c137996411574ce478a7a1886dcc0;p=electron.git Release resources in browser when renderer view is gonna unloaded. --- diff --git a/browser/atom/objects_registry.coffee b/browser/atom/objects_registry.coffee index fb886eb0..f921eb64 100644 --- a/browser/atom/objects_registry.coffee +++ b/browser/atom/objects_registry.coffee @@ -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 diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index 8c8eed65..bbcc2f3c 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -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() diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 4b74be89..23f5c6ba 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -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