我有一個應用程序拋出GKSession並在各種條件下(連接超時,會話失敗等)產生新的應用程序。不過,我得到了內存泄漏,並且在重新連接幾次循環之後,它有時會崩潰。GKSession alloc/release/alloc =泄漏和崩潰
這裏是我的代碼:
- (void) netConnect:(id) sender {
NSLog(@"allocating GKSession");
currentSession = [[GKSession alloc] initWithSessionID:nil displayName:nil sessionMode:GKSessionModePeer];
currentSession.delegate = self;
currentSession.available = YES;
currentSession.disconnectTimeout = 0;
[currentSession setDataReceiveHandler: self withContext:nil];
}
- (void) netDisconnect:(id) sender {
NSLog(@"DISCONNECTING BY REQUEST");
[currentSession disconnectFromAllPeers];
[currentSession setAvailable:NO];
[currentSession setDelegate:nil];
[currentSession setDataReceiveHandler:nil withContext:nil];
[currentSession release];
currentSession = nil;
}
有這麼等待成功連接的定時器;如果它沒有得到,則調用netDisconnect,然後在5秒的NSTimer延遲後再次調用netConnect。
我越來越泄露GKList,GKTable和GKAutoPeerIDTable對象,像這樣的崩潰(在ALLOC後總是發生):
Date/Time: 2010-09-05 09:35:59.426 -0700
OS Version: iPhone OS 4.0.2 (8A400)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000a
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286c objc_msgSend + 16
1 CoreFoundation 0x000756ea __CFCopyFormattingDescription + 174
2 CoreFoundation 0x00081c8e __CFStringAppendFormatCore + 8666
3 CoreFoundation 0x000146ac _CFStringCreateWithFormatAndArgumentsAux + 64
4 CoreFoundation 0x00014660 CFStringCreateWithFormatAndArguments + 16
5 CoreFoundation 0x0001463c CFStringCreateWithFormat + 16
6 SystemConfiguration 0x00003272 SCDynamicStoreCreateWithOptions + 62
7 SystemConfiguration 0x000033d0 SCDynamicStoreCreate + 12
8 GameKitServices 0x000020ce gckRegisterForNetworkChanges + 154
9 GameKitServices 0x000035c0 GCKSessionCreate + 788
10 GameKitServices 0x00035e7a -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 274
11 GameKit 0x0000fda8 -[GKSession initWithSessionID:displayName:sessionMode:] + 76
這裏的另一個問題:
Sun Sep 5 10:28:52 thinner someapp[424] <Warning>: allocating GKSession
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: -[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710
Sun Sep 5 10:28:52 thinner someapp[424] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData UTF8String]: unrecognized selector sent to instance 0x10a710'
*** Call stack at first throw:
(
0 CoreFoundation 0x31a9ffd3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3428a8a5 objc_exception_throw + 24
2 CoreFoundation 0x31aa3a77 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x31aa2f15 ___forwarding___ + 508
4 CoreFoundation 0x31a35680 _CF_forwarding_prep_0 + 48
5 GameKitServices 0x327aff13 -[GKSessionInternal initWithSessionID:displayName:session:sessionMode:] + 426
6 GameKit 0x31c15daf -[GKSession initWithSessionID:displayName:sessionMode:] + 82
7 someapp 0x0000584b -[MainViewController netConnect:] + 126
問題:
•這是釋放和重新分配GKSession的正確方法嗎?
•我是不是應該先拆除並重新分配連接之間的GKSession?
我傾向於GameKit的越野車,但不釋放會話是更好的方式去反正當意圖是不斷嘗試連接或重新連接。 – 2010-09-06 06:37:57
我沒有你的答案,但我已經擺弄GKSession兩天了,是的,它似乎經常崩潰,經常在dealloc上...看起來真的很糟糕... – Jonny 2010-10-04 10:07:40