Release resources in browser when renderer view is gonna unloaded.
This commit is contained in:
parent
a674572dd4
commit
31d6be0e63
3 changed files with 14 additions and 0 deletions
|
@ -31,6 +31,10 @@ class ObjectsStore
|
||||||
@stores[key] = new ObjectsStore unless @stores[key]?
|
@stores[key] = new ObjectsStore unless @stores[key]?
|
||||||
@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
|
# 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.
|
# every object created in browser will have a unique id in weak map.
|
||||||
objectsWeakMap = new IDWeakMap
|
objectsWeakMap = new IDWeakMap
|
||||||
|
@ -72,3 +76,6 @@ exports.getAllWindows = () ->
|
||||||
|
|
||||||
exports.remove = (processId, routingId, storeId) ->
|
exports.remove = (processId, routingId, storeId) ->
|
||||||
ObjectsStore.forRenderView(processId, routingId).remove storeId
|
ObjectsStore.forRenderView(processId, routingId).remove storeId
|
||||||
|
|
||||||
|
exports.clear = (processId, routingId) ->
|
||||||
|
ObjectsStore.releaseForRenderView processId, routingId
|
||||||
|
|
|
@ -43,6 +43,9 @@ ipc.on 'ATOM_BROWSER_GLOBAL', (event, processId, routingId, name) ->
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
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) ->
|
ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) ->
|
||||||
try
|
try
|
||||||
windows = objectsRegistry.getAllWindows()
|
windows = objectsRegistry.getAllWindows()
|
||||||
|
|
|
@ -53,6 +53,10 @@ metaToValue = (meta) ->
|
||||||
|
|
||||||
ret
|
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.
|
# Get remote module.
|
||||||
exports.require = (module) ->
|
exports.require = (module) ->
|
||||||
meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module
|
meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue