Commit b5fcab9b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 12621777
...@@ -65,7 +65,7 @@ type Ref struct { ...@@ -65,7 +65,7 @@ type Ref struct {
// NewRef creates new weak reference pointing to obj. // NewRef creates new weak reference pointing to obj.
// //
// XXX + onrelease callback? // TODO + onrelease callback?
func NewRef(obj interface{}) *Ref { func NewRef(obj interface{}) *Ref {
// since starting from ~ Go1.4 the GC is precise, we can save interface // since starting from ~ Go1.4 the GC is precise, we can save interface
// pointers to uintptr and that won't prevent GC from garbage // pointers to uintptr and that won't prevent GC from garbage
......
...@@ -53,9 +53,8 @@ func TestIface(t *testing.T) { ...@@ -53,9 +53,8 @@ func TestIface(t *testing.T) {
} }
} }
func TestWeakRef(t *testing.T) { func TestWeakRef(t *testing.T) {
type T struct { _ [8]int64 } // large enough not to go into tinyalloc type T struct{ _ [8]int64 } // large enough not to go into tinyalloc
p := new(T) p := new(T)
w := NewRef(p) w := NewRef(p)
...@@ -68,16 +67,15 @@ func TestWeakRef(t *testing.T) { ...@@ -68,16 +67,15 @@ func TestWeakRef(t *testing.T) {
} }
} }
// perform GC + give finalizers a chancet to run. // perform GC + give finalizers a chance to run.
GC := func() { GC := func() {
runtime.GC() runtime.GC()
// GC only queues finalizers, not runs them directly. Give it // GC only queues finalizers, not runs them directly. Give it
// some time so that finalizers could have been run. // some time so that finalizers could have been run.
time.Sleep(10*time.Millisecond) // XXX hack time.Sleep(10 * time.Millisecond) // XXX hack
} }
assertEq(w.state, objLive) assertEq(w.state, objLive)
assertEq(w.Get(), p) assertEq(w.Get(), p)
assertEq(w.state, objGot) assertEq(w.state, objGot)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment