From 619a9c236bf79c63d955490c0803833004a47154 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sun, 21 Jun 2020 06:44:06 -0700 Subject: Add a way to cleanly shut down the library (#578) This change adds the Shutdown() method, so that the library can be cleanly shut down. This helps significanly reduce the amount of noise in the leak detector. --- handles.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'handles.go') diff --git a/handles.go b/handles.go index d27d3c3..c0d4b3c 100644 --- a/handles.go +++ b/handles.go @@ -43,6 +43,16 @@ func (v *HandleList) Untrack(handle unsafe.Pointer) { v.Unlock() } +// Clear stops tracking all the managed pointers. +func (v *HandleList) Clear() { + v.Lock() + for handle := range v.handles { + delete(v.handles, handle) + C.free(handle) + } + v.Unlock() +} + // Get retrieves the pointer from the given handle func (v *HandleList) Get(handle unsafe.Pointer) interface{} { v.RLock() -- cgit v1.2.3