Plug various leaks of capability references.

In all cases, the capabilities would eventually be garbage collected, but if a user explicitly called .close() in hopes of dropping a reference proactively, it could be ignored because a leaked reference still existed.