Hi Experts,
I am working on a application where I am calling Objective-C Core WLAN API from golang with below code,
darwin_lib.m
void ConnectWiFi(char * cInterfacename, char * cSSID, char * cSecurity, char *cSubsecurity, char * cPassphrase, char * cOnexuser, char * cOnexpass) {
@autoreleasepool {
NSString * interfacename = [[NSString alloc] initWithUTF8String:cInterfacename];
NSString * ssid = [[NSString alloc] initWithUTF8String:cSSID];
NSString * security = [[NSString alloc] initWithUTF8String:cSecurity];
NSString * subsecurity = [[NSString alloc] initWithUTF8String:cSubsecurity];
NSString * passphrase = [[NSString alloc] initWithUTF8String:cPassphrase];
NSString * onexuser = [[NSString alloc] initWithUTF8String:cOnexuser];
NSString * onexpass = [[NSString alloc] initWithUTF8String:cOnexpass];
NSError * connecterr = nil;
CWWiFiClient * cwwificlient = [CWWiFiClient sharedWiFiClient];
CWInterface *a = [cwwificlient interfaceWithName:interfacename];
NSSet<CWNetwork *> * network = [a scanForNetworksWithName:ssid error:&connecterr];
**** some more code *****
BOOL result = [a associateToEnterpriseNetwork:network.anyObject identity:nil username:onexuser password:onexpass error:&connecterr];
main.go
package main
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework CoreWLAN
// #cgo LDFLAGS: -framework Foundation
// #include "clib.h"
import "C"
import "fmt"
func main() {
var status C.int = C.ConnectWiFi()
time.Sleep(20)
*** some more code and long running process ***
}
Now what I am trying to understand here from memory release point of view is,
- Is object created in C code will be freed once I reach time.Sleep(20) e.g
cwwificlient
a
spcifically to Core WLAN side or do I have to call release specifically on object?
- I tried calling release on
cwwificlient
and program is crashing on second execution, not sure why it would crash on only second execution, why not first time itself? - I tried calling release on
a
and program is not crashing.
Do I have to free all the Core WLAN related object myself or autoreleasepool will take care of it?
- As whole code is inside autoreleasepool, will all the objects be released on it's own even though function is being called from go code? As go's garbage collector has no idea how many objects C code created so go's garbage collector won't be of any help here
- Is autoreleasepool, can also take care of releasing any alloc object e.g
ssid
created inside C code ?