Skip to content

update docs to clarify that users would be better off not relying on SetFinalizer #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ func (p *Parser) Debug() {

// Close should be called to ensure that all the memory used by the parse is freed.
//
// As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
// parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
// As a backstop, the constructor sets this to run as the type's finalizer, via runtime.SetFinalizer.
// However, this doesn't guarantee the finalizer will run, especially if your Go heap usage is not forcing GC regularly,
// and the process may use unexpected amounts of memory
func (p *Parser) Close() {
if !p.isClosed {
C.ts_parser_delete(p.c)
Expand Down Expand Up @@ -304,8 +305,9 @@ func (t *Tree) cachedNode(ptr C.TSNode) *Node {

// Close should be called to ensure that all the memory used by the tree is freed.
//
// As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
// parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
// As a backstop, the constructor sets this to run as the type's finalizer, via runtime.SetFinalizer.
// However, this doesn't guarantee the finalizer will run, especially if your Go heap usage is not forcing GC regularly,
// and the process may use unexpected amounts of memory
func (t *BaseTree) Close() {
if !t.isClosed {
C.ts_tree_delete(t.c)
Expand Down Expand Up @@ -621,8 +623,9 @@ func NewTreeCursor(n *Node) *TreeCursor {
// Close should be called to ensure that all the memory used by the tree cursor
// is freed.
//
// As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
// parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
// As a backstop, the constructor sets this to run as the type's finalizer, via runtime.SetFinalizer.
// However, this doesn't guarantee the finalizer will run, especially if your Go heap usage is not forcing GC regularly,
// and the process may use unexpected amounts of memory
func (c *TreeCursor) Close() {
if !c.isClosed {
C.ts_tree_cursor_delete(c.c)
Expand Down Expand Up @@ -867,8 +870,9 @@ func NewQuery(pattern []byte, lang *Language) (*Query, error) {

// Close should be called to ensure that all the memory used by the query is freed.
//
// As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
// parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
// As a backstop, the constructor sets this to run as the type's finalizer, via runtime.SetFinalizer.
// However, this doesn't guarantee the finalizer will run, especially if your Go heap usage is not forcing GC regularly,
// and the process may use unexpected amounts of memory
func (q *Query) Close() {
if !q.isClosed {
C.ts_query_delete(q.c)
Expand Down Expand Up @@ -990,8 +994,10 @@ func (qc *QueryCursor) SetPointRange(startPoint Point, endPoint Point) {

// Close should be called to ensure that all the memory used by the query cursor is freed.
//
// As the constructor in go-tree-sitter would set this func call through runtime.SetFinalizer,
// parser.Close() will be called by Go's garbage collector and users would not have to call this manually.
// As a backstop, the constructor sets this to run as the type's finalizer, via runtime.SetFinalizer.
// However, this doesn't guarantee the finalizer will run, especially if your Go heap usage is not forcing GC regularly,
// and the process may use unexpected amounts of memory
// before your process runs out of memory.
func (qc *QueryCursor) Close() {
if !qc.isClosed {
C.ts_query_cursor_delete(qc.c)
Expand Down