DecRef decrements the reference count for the specified handle and removes it if the reference count goes to zero.
(handle CGoHandle)
| 130 | // DecRef decrements the reference count for the specified handle |
| 131 | // and removes it if the reference count goes to zero. |
| 132 | func DecRef(handle CGoHandle) { |
| 133 | if handle < 1 { |
| 134 | return |
| 135 | } |
| 136 | mu.Lock() |
| 137 | defer mu.Unlock() |
| 138 | if handles == nil { |
| 139 | return |
| 140 | } |
| 141 | ghc := GoHandle(handle) |
| 142 | if _, exists := handles[ghc]; !exists { |
| 143 | return |
| 144 | } |
| 145 | counts[ghc]-- |
| 146 | switch cnt := counts[ghc]; { |
| 147 | case cnt == 0: |
| 148 | delete(counts, ghc) |
| 149 | delete(handles, ghc) |
| 150 | if trace { |
| 151 | fmt.Printf("gopy DecRef: %d\n", handle) |
| 152 | } |
| 153 | case cnt < 0: |
| 154 | panic(fmt.Sprintf("gopy DecRef ref count %v for handle: %v, ifc %v", cnt, ghc, handles[ghc])) |
| 155 | default: |
| 156 | if trace { |
| 157 | fmt.Printf("gopy DecRef: %d: %d\n", handle, cnt) |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // IncRef increments the reference count for the specified handle. |
| 163 | func IncRef(handle CGoHandle) { |