From d43561fbf711896f5ce33f409c6000946416a82b Mon Sep 17 00:00:00 2001 From: Carlos Martín Nieto Date: Wed, 6 Mar 2013 01:43:48 +0100 Subject: Free Git objects via finalizers or manually Provide a manual way of freeing objects, but set finalizers for them in case the user does not want to worry about memory management, which would be useful for commits or trees, which sare typically small. When the objects are freed manually, the finalizer is unset to avoid double-freeing, mimicking what the go runtime does. --- commit.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'commit.go') diff --git a/commit.go b/commit.go index 855ed87..779ebd7 100644 --- a/commit.go +++ b/commit.go @@ -9,6 +9,7 @@ extern int _go_git_treewalk(git_tree *tree, git_treewalk_mode mode, void *ptr); import "C" import ( + "runtime" "time" ) @@ -32,6 +33,8 @@ func (c *Commit) Tree() (*Tree, error) { if err < 0 { return nil, LastError() } + + runtime.SetFinalizer(tree, (*Tree).Free) return tree, nil } -- cgit v1.2.3