Tell browser to release remote object when the object is GCed.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Apr 2013 11:26:31 +0000 (19:26 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Apr 2013 11:28:04 +0000 (19:28 +0800)
browser/atom/rpc_server.coffee
renderer/api/lib/remote.coffee

index c2d2e14..76a5ccb 100644 (file)
@@ -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
index ebc8da4..9653d2b 100644 (file)
@@ -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