From: Cheng Zhao Date: Thu, 25 Apr 2013 11:26:31 +0000 (+0800) Subject: Tell browser to release remote object when the object is GCed. X-Git-Tag: v0.1.0~256 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3f6f2f4beacaa8ced12e3ad12c7095ac1f240dac;p=electron.git Tell browser to release remote object when the object is GCed. --- diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index c2d2e14a..76a5ccbc 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -62,3 +62,6 @@ ipc.on 'ATOM_INTERNAL_MEMBER_GET', (event, process_id, routing_id, id, name) -> event.result = new PlainObject(objectsRegistry.get(id)[name]) catch e event.result = type: 'error', value: e.message + +ipc.on 'ATOM_INTERNAL_DESTROY', (process_id, routing_id, id) -> + objectsRegistry.remove id diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index ebc8da41..9653d2b8 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -45,8 +45,14 @@ generateFromPainObject = (plain) -> ret = ipc.sendChannelSync 'ATOM_INTERNAL_MEMBER_GET', plain.id, member.name generateFromPainObject ret + # Track delegate object's life time, and tell the browser to clean up + # when the object is GCed. + v8_util.setDestructor ret, -> + ipc.sendChannel 'ATOM_INTERNAL_DESTROY', plain.id + ret +# Get remote module. exports.require = (module) -> plain = ipc.sendChannelSync 'ATOM_INTERNAL_REQUIRE', module generateFromPainObject plain