diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-28 17:32:55 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-28 17:32:55 -0500 |
| commit | e4339d3c49453794dee1b9f0f3a48bd7ce8cae6f (patch) | |
| tree | 8df7f373a7aa2efde39749626c4776f0c49918b0 | |
| parent | 56a436bc804539db271471b357c5b3e5d6465238 (diff) | |
Set up a NSAutoreleasePool for notify() to suppress memory leak warnings.
| -rw-r--r-- | darwintest/runtimetest.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/darwintest/runtimetest.go b/darwintest/runtimetest.go index e84dc89..d3cf3c1 100644 --- a/darwintest/runtimetest.go +++ b/darwintest/runtimetest.go @@ -98,6 +98,10 @@ func notify(source string) { csource := C.CString(source) defer C.free(unsafe.Pointer(csource)) + // we need to make an NSAutoreleasePool, otherwise we get leak warnings on stderr + pool := C.objc_msgSend_noargs( + objc_getClass("NSAutoreleasePool"), + sel_getUid("new")) src := C.objc_msgSend_strarg( objc_getClass("NSString"), sel_getUid("stringWithUTF8String:"), @@ -107,7 +111,9 @@ func notify(source string) { sel_getUid("performSelectorOnMainThread:withObject:waitUntilDone:"), notesel, src, - C.BOOL(C.FALSE)) // don't wait; we're using a channel for this (in the final ui code) + C.BOOL(C.TRUE)) // wait so we can properly drain the autorelease pool; on other platforms we wind up waiting anyway (since the main thread can only handle one thing at a time) so + C.objc_msgSend_noargs(pool, + sel_getUid("release")) } func main() { |
