Release render view's remote objects when it's deleted.

Privously we release them when the window is unloaded, which is not
correct since a render view can have multiple windows (or js contexts)
and when the unload event is emitted the render view could already have
gone.

This PR does the cleaning work purely in browser, so here is no need to
worry about renderer's life time.
This commit is contained in:
Cheng Zhao 2013-12-06 14:44:25 +08:00
parent e9e90b481a
commit 623e0f3ae4
8 changed files with 28 additions and 11 deletions

View file

@ -2,7 +2,6 @@ ipc = require 'ipc'
CallbacksRegistry = require 'callbacks-registry'
v8Util = process.atomBinding 'v8_util'
currentContextExist = true
callbacksRegistry = new CallbacksRegistry
# Convert the arguments object into an array of meta data.
@ -82,7 +81,6 @@ metaToValue = (meta) ->
# Track delegate object's life time, and tell the browser to clean up
# when the object is GCed.
v8Util.setDestructor ret, ->
return unless currentContextExist
ipc.sendChannel 'ATOM_BROWSER_DEREFERENCE', meta.storeId
# Remember object's id.
@ -98,11 +96,6 @@ ipc.on 'ATOM_RENDERER_CALLBACK', (id, args) ->
ipc.on 'ATOM_RENDERER_RELEASE_CALLBACK', (id) ->
callbacksRegistry.remove id
# Release all resources of current render view when it's going to be unloaded.
window.addEventListener 'unload', (event) ->
currentContextExist = false
ipc.sendChannelSync 'ATOM_BROWSER_RELEASE_RENDER_VIEW'
# Get remote module.
# (Just like node's require, the modules are cached permanently, note that this
# is safe leak since the object is not expected to get freed in browser)