-
Notifications
You must be signed in to change notification settings - Fork 168
/
cgoMemory_test.go
70 lines (51 loc) · 945 Bytes
/
cgoMemory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package gmf
import (
// "log"
"testing"
)
type SubData struct {
CgoMemoryManage
Id int32
Name [16]byte
}
type Data struct {
SubData
abc int
}
var dataIsFree bool = false
var subDataIsFree bool = false
func (d *Data) Free() {
// log.Printf(" Data Free(%p) retainCount=%d",d,d.RetainCount())
dataIsFree = true
}
func (d *SubData) Free() {
// log.Printf(" SubData Free(%p) retainCount=%d",d,d.RetainCount())
subDataIsFree = true
}
func TestCgoMemory(t *testing.T) {
var abc *Data
abc = new(Data)
sss := SubData{Id: 12}
Retain(abc)
if 2 != abc.RetainCount() {
t.Fatal("has error.")
}
Release(abc)
if 1 != abc.RetainCount() {
t.Fatal("has error.")
}
Release(abc)
if 0 != abc.RetainCount() {
t.Fatal("has error.")
}
if !dataIsFree {
t.Fatal("Data not run Free.")
}
Release(&sss)
if 0 != sss.RetainCount() {
t.Fatal("has error.")
}
if !subDataIsFree {
t.Fatal("subData not run Free.")
}
}