@@ -11,7 +11,7 @@ import (
1111
1212type Refcount struct {
1313 count atomic.Int64
14- dependencies []* * Refcount
14+ dependencies []unsafe. Pointer
1515 buffers []* * Buffer
1616 derived []unsafe.Pointer
1717}
@@ -20,7 +20,7 @@ type Refcount struct {
2020// When this object is completely unreferenced, all dependencies will
2121// be unreferenced by it and, if this was the only object still
2222// referencing them, they will be freed as well, recursively.
23- func (r * Refcount ) ReferenceDependency (d ... * * Refcount ) {
23+ func (r * Refcount ) ReferenceDependency (d ... unsafe. Pointer ) {
2424 r .dependencies = d
2525}
2626
@@ -31,9 +31,8 @@ func (r *Refcount) ReferenceBuffer(b ...**Buffer) {
3131 r .buffers = b
3232}
3333
34- // Must only be called once per object, with a list of pointers that are
35- // _derived from_ allocations owned by or referenced by this object.
36- // When this object is unreferenced, all such pointers will be nilled.
34+ // Must only be called once per object, with a list of pointers that need to be
35+ // cleared when the object becomes unreferenced.
3736// Note: this needs the _address of_ the pointers to nil, _not_ the pointers
3837// themselves!
3938func (r * Refcount ) ReferenceDerived (p ... unsafe.Pointer ) {
@@ -52,8 +51,16 @@ func (r *Refcount) Release() {
5251 * buffer = nil
5352 }
5453 for _ , dependency := range r .dependencies {
55- (* dependency ).Release ()
56- * dependency = nil
54+ ptr := (* unsafe .Pointer )(dependency )
55+ if * ptr != nil {
56+ // Ptr should be a **T, where T has a Refcount
57+ // embedded at the front.
58+ // So, if *ptr != nil, we should be able to cast *ptr
59+ // to a *Refcount.
60+ rc := (* Refcount )(* ptr )
61+ rc .Release ()
62+ * ptr = nil
63+ }
5764 }
5865 r .buffers = nil
5966 r .dependencies = nil
0 commit comments