-
-
Notifications
You must be signed in to change notification settings - Fork 111
Ref Counting
davidhubbard edited this page Nov 15, 2023
·
8 revisions
⚠️ NOTE: This page is WIP. All the essential information is there, but we really ought to make it more digestible. If something doesn't make sense, please don't give up. Drop us a line, instead!
- Each reference to a capability has an "owner." The owner is responsible for calling
.Release()
on the reference when it is no longer needed. - Generated
Foo_ServerToClient
methods return a capability reference owned by the caller. - The
.AddRef()
method returns a new reference to the same underlying capability, which is owned by the caller. - Calling
foo.Bar(baz)
wherefoo
andbaz
are capabilities transfers ownership ofbaz
tofoo
. Thefoo
instance will callbaz.Release()
when finished. - Capabilities received as arguments to an RPC handler are borrowed and will be released when the RPC handler returns. Calling
AddRef()
returns a capability (owned by the caller) that may persist beyond the scope of the RPC handler, per rule 3. - Capabilities returned by a method call are owned by the results struct, and live until that call's ReleaseFunc is invoked.
- [ BUG ] Passing the last reference for a capability to itself causes a deadlock.
Golang already handles object reference counting and garbage-collecting them after they are not used any more.
Capnproto adds to that by closely tying state to the Actor in Actor Model theory and explicitly garbage collecting it. This helps debuggability.