In many cases, a Bus may need to be maintained as long as multiple objects are using it. AutoReleaseBus maintains an IdentitySet of "clients." When another object is using this bus, it should add itself as a client. When it no longer needs the bus, it should remove itself. When all clients are removed, the bus will free itself.
If the AutoReleaseBus is added as a dependent (addDependant
), then the client object can broadcast theObject.changed(\didFree)
and the AutoReleaseBus will remove the client.
Use Bus: *audio and Bus: *control to create instances.
Add a client object.
client |
Some object using the bus. |
Remove the client object, and automatically free the bus if all clients have been removed.
client |
Some object using the bus. |
Forced "free," disregarding existing clients.
... why |
An optional annotation, to be broadcast to any dependents. |