Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felixge/go-cgo-finalizer
Demonstrates using runtime.SetFinalizer to free cgo memory allocations.
https://github.com/felixge/go-cgo-finalizer
Last synced: about 2 months ago
JSON representation
Demonstrates using runtime.SetFinalizer to free cgo memory allocations.
- Host: GitHub
- URL: https://github.com/felixge/go-cgo-finalizer
- Owner: felixge
- Created: 2013-07-17T14:41:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-07-17T14:46:35.000Z (over 11 years ago)
- Last Synced: 2024-10-11T15:19:24.315Z (2 months ago)
- Language: Go
- Size: 102 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Can runtime.SetFinalizer be used to free cgo memory allocations?
This repository aims to answer this question with the provided `finalizer.go`
example by:* Running a tight loop that allocates a struct that holds a pointer to a C string
* Using runtime.SetFinalizer() to free this memory
* Printing the current RSS memory usage, as well as alloc/free countersAs far as this setup is concerned, the answer is: Yes, runtime.SetFinalizer()
works well for automatically free()'ing cgo memory allocations!Sample result for `go version go1.1.1 darwin/amd64`:
```
sample rss_mb allocs frees
1 2 10000 9989
2 3 20000 19985
3 3 30000 29981
4 3 40000 39998
5 3 50000 49994
6 3 60000 59990
7 3 70000 69986
8 3 80000 79982
9 3 90000 89978
10 3 100000 99995
11 3 110000 109991
12 3 120000 119987
13 3 130000 129983
14 3 140000 139979
15 3 150000 149996
16 3 160000 159992
17 3 170000 169988
18 3 180000 179984
19 3 190000 189980
20 3 200000 199997
21 3 210000 209993
22 3 220000 219989
23 3 230000 229985
24 3 240000 239981
25 3 250000 249998
26 3 260000 259994
27 3 270000 269990
28 3 280000 279986
29 3 290000 289982
30 3 300000 299978
31 3 310000 309995
32 3 320000 319991
33 3 330000 329987
34 3 340000 339983
35 3 350000 349979
36 3 360000 359996
37 3 370000 369992
38 3 380000 379988
39 3 390000 389984
40 3 400000 399980
41 3 410000 409997
42 3 420000 419993
43 3 430000 429989
44 3 440000 439985
45 3 450000 449981
46 3 460000 459998
47 3 470000 469994
48 3 480000 479990
49 3 490000 489986
50 3 500000 499982
51 3 510000 509978
52 3 520000 519995
53 3 530000 529991
54 3 540000 539987
55 3 550000 549983
56 3 560000 559979
57 4 570000 569996
58 4 580000 579992
59 4 590000 589988
60 4 600000 599984
61 4 610000 609980
62 4 620000 619997
63 4 630000 629993
64 4 640000 639989
65 4 650000 649985
66 4 660000 659981
67 4 670000 669998
68 4 680000 679994
69 4 690000 689990
70 4 700000 699986
71 4 710000 709982
72 4 720000 719978
73 4 730000 729995
74 4 740000 739991
75 4 750000 749987
76 4 760000 759983
77 4 770000 769979
78 4 780000 779996
79 4 790000 789992
80 4 800000 799988
81 4 810000 809984
82 4 820000 819980
83 4 830000 829997
84 4 840000 839993
85 4 850000 849989
86 4 860000 859985
87 4 870000 869981
88 4 880000 879998
89 4 890000 889994
90 4 900000 899990
91 4 910000 909986
92 4 920000 919982
93 4 930000 929978
94 4 940000 939995
95 4 950000 949991
96 4 960000 959987
97 4 970000 969983
98 4 980000 979979
99 4 990000 989996
100 4 1000000 999992
```