Documentation ¶
Overview ¶
Package refs defines an interface for reference counted objects.
Index ¶
- Variables
- func DoLeakCheck()
- func DoRepeatedLeakCheck()
- func FormatStack(pcs []uintptr) string
- func LeakCheckEnabled() bool
- func LogDecRef(obj CheckedObject, refs int64)
- func LogIncRef(obj CheckedObject, refs int64)
- func LogTryIncRef(obj CheckedObject, refs int64)
- func OnExit()
- func RecordStack() []uintptr
- func Register(obj CheckedObject)
- func SetLeakMode(mode LeakMode)
- func Unregister(obj CheckedObject)
- type CheckedObject
- type LeakMode
- type RefCounter
- type TryRefCounter
Constants ¶
This section is empty.
Variables ¶
var CleanupSync sync.WaitGroup
CleanupSync is used to wait for async cleanup actions.
Functions ¶
func DoLeakCheck ¶
func DoLeakCheck()
DoLeakCheck iterates through the live object map and logs a message for each object. It should be called when no reference-counted objects are reachable anymore, at which point anything left in the map is considered a leak. On multiple calls, only the first call will perform the leak check.
func DoRepeatedLeakCheck ¶
func DoRepeatedLeakCheck()
DoRepeatedLeakCheck is the same as DoLeakCheck except that it can be called multiple times by the caller to incrementally perform leak checking.
func FormatStack ¶
FormatStack converts the given stack into a readable format.
func LeakCheckEnabled ¶
func LeakCheckEnabled() bool
LeakCheckEnabled returns whether leak checking is enabled. The following functions should only be called if it returns true.
func LogDecRef ¶
func LogDecRef(obj CheckedObject, refs int64)
LogDecRef logs a reference decrement.
func LogIncRef ¶
func LogIncRef(obj CheckedObject, refs int64)
LogIncRef logs a reference increment.
func LogTryIncRef ¶
func LogTryIncRef(obj CheckedObject, refs int64)
LogTryIncRef logs a successful TryIncRef call.
func OnExit ¶
func OnExit()
OnExit is called on sandbox exit. It runs GC to enqueue refcount finalizers, which check for reference leaks. There is no way to guarantee that every finalizer will run before exiting, but this at least ensures that they will be discovered/enqueued by GC.
func RecordStack ¶
func RecordStack() []uintptr
RecordStack constructs and returns the PCs on the current stack.
func SetLeakMode ¶
func SetLeakMode(mode LeakMode)
SetLeakMode configures the reference leak checker.
func Unregister ¶
func Unregister(obj CheckedObject)
Unregister removes obj from the live object map.
Types ¶
type CheckedObject ¶
type CheckedObject interface { // RefType is the type of the reference-counted object. RefType() string // LeakMessage supplies a warning to be printed upon leak detection. LeakMessage() string // LogRefs indicates whether reference-related events should be logged. LogRefs() bool }
CheckedObject represents a reference-counted object with an informative leak detection message.
type LeakMode ¶
type LeakMode uint32
LeakMode configures the leak checker.
const ( // NoLeakChecking indicates that no effort should be made to check for // leaks. NoLeakChecking LeakMode = iota // LeaksLogWarning indicates that a warning should be logged when leaks // are found. LeaksLogWarning // LeaksPanic indidcates that a panic should be issued when leaks are found. LeaksPanic )
type RefCounter ¶
type RefCounter interface { // IncRef increments the reference counter on the object. IncRef() // DecRef decrements the object's reference count. Users of refs_template.Refs // may specify a destructor to be called once the reference count reaches zero. DecRef(ctx context.Context) }
RefCounter is the interface to be implemented by objects that are reference counted.
type TryRefCounter ¶
type TryRefCounter interface { RefCounter // TryIncRef attempts to increment the reference count, but may fail if all // references have already been dropped, in which case it returns false. If // true is returned, then a valid reference is now held on the object. TryIncRef() bool }
TryRefCounter is like RefCounter but allow the ref increment to be tried.