- All Known Implementing Classes:
- SSTableReader
public interface RefCounted
An object that needs ref counting does the following:
- defines a Tidy object that will cleanup once it's gone,
(this must retain no references to the object we're tracking (only its resources and how to clean up))
- implements RefCounted
- encapsulates a RefCounted.Impl, to which it proxies all calls to RefCounted behaviours
- ensures no external access to the encapsulated Impl, and permits no references to it to leak
- users must ensure no references to the sharedRef leak, or are retained outside of a method scope either.
(to ensure the sharedRef is collected with the object, so that leaks may be detected and corrected)
This class' functionality is achieved by what may look at first glance like a complex web of references,
but boils down to:
Target --> Impl --> sharedRef --> [RefState] <--> RefCountedState --> Tidy
^ ^
| |
Ref ----------------------------------- |
|
Global -------------------------------------------------
So that, if Target is collected, Impl is collected and, hence, so is sharedRef.
Once ref or sharedRef are collected, the paired RefState's release method is called, which if it had
not already been called will update RefCountedState and log an error.
Once the RefCountedState has been completely released, the Tidy method is called and it removes the global reference
to itself so it may also be collected.