All
У меня есть контроллер представления (назовем его testViewController), который вызывает метод в другом классе (сканирование имени класса, имя метода initNetworkCommunication).
Вот метод кнопки контроллера вида:
-(IBAction) test
{
Scan *canConnect = [[Scan alloc] init];
[canConnect initNetworkCommunication];
}
А вот и класс
//scan.h
@interface Scan : NSObject <NSStreamDelegate>
{
NSInputStream *inputStream;
NSOutputStream *outputStream;
}
-(void) scan;
-(void) initNetworkCommunication;
@property (nonatomic, retain) NSInputStream *inputStream;
@property (nonatomic, retain) NSOutputStream *outputStream;
@end
//scan.m
#import "Scan.h"
@implementation Scan
@synthesize inputStream, outputStream;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
}
return self;
}
-(void) initNetworkCommunication
{
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.17.1", 2004, &readStream, &writeStream);
NSLog(@"readStream %@", readStream);
NSLog(@"writeStream %@", writeStream);
inputStream = (NSInputStream *) readStream;
outputStream = (NSOutputStream *) writeStream;//this __strong may work!
NSLog(@"inputStream %@", inputStream);
NSLog(@"outputStream %@", outputStream);
[inputStream setDelegate:self];
[outputStream setDelegate:self];
[inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inputStream open];
[outputStream open];
NSLog(@"She be opened, sir!");
return;
}
//more code is here, dealloc, etc
Я получаю EXC_BAD_ACCESS, и когда я включаю NSZombieEnable, мой сеанс отладки выглядит так:
2011-07-15 13:09:46.210 Project[1176:f203] readStream <__NSCFInputStream: 0x6e7a2a0>
2011-07-15 13:09:46.212 Project[1176:f203] writeStream <__NSCFOutputStream: 0x6e7a340>
2011-07-15 13:09:46.213 Project[1176:f203] inputStream <__NSCFInputStream: 0x6e7a2a0>
2011-07-15 13:09:46.214 Project[1176:f203] outputStream <__NSCFOutputStream: 0x6e7a340>
2011-07-15 13:09:46.215 Project[1176:f203] She be opened, sir!
2011-07-15 13:09:46.220 Project[1176:f203] *** -[Scan respondsToSelector:]: message sent to deallocated instance 0x6e79b20
Current language: auto; currently objective-c
(gdb)
Он падает на три звездочки, и это мое сообщение зомби.
Что мне делать?
РЕДАКТИРОВАТЬ: после запуска программы в инструментах, я не вижу утечек памяти. То, что меня привлекает, отображается в инструментах как SocketStream :: dispatchSignalFromSocketCallbackUnlocked (SocketStream)