mattn/go-ole — pull request #21 by stefanschneider (2014-07-15 11:00:06+00:00)
Title: Finalize result from invoke method with VariantClear

I had some serious leaks when invoking ComVisible .NET methods that return string. After digging a bit deeper in this library I saw that the clean for the returned Variant is left to the user.

Adding a finalizer solved my leaks with the string, even though the doc for SetFinalizer states the following : "so typically they are useful only for releasing non-memory resources associated with an object during a long-running program." http://golang.org/pkg/runtime/#SetFinalizer

Maybe another solution would be to expose VariantClear to the user and inform his that he has to call the method after he is finished with the return value.

Even if the user would cleanup the Variant it won't hurt to have the finalizer set (except some tiny CPU overhead).

Also, check out this article: https://github.com/felixge/go-cgo-finalizer. It looks like the go finalizer is would be of some help even for memory resources.

Please give me your thoughts.