Memory management problem in using of NSConnection
Memory management problem in using of NSConnection
- Subject: Memory management problem in using of NSConnection
- From: email@hidden
- Date: Fri, 30 Nov 2001 15:16:24 -0700
Hello all,
I got quite confused about memory management while using NSConnection.
I have a server application with a controller.m:
-(void)awakeFromNib
{
NSPort *receivePort = nil;
NSConnection *conn;
receivePort = [[NSMachPort alloc] init];
conn = [[NSConnection alloc] initWithReceivePort:receivePort
sendPort:nil];
[conn setRootObject:self];
//[receivePort release];
//[conn release];
}
According to the memory management rule of cocoa, I think I should add
[receivePort release]; [conn release]; to the function because I
alloc them, but if I do so my client application can't work
properly(without these two sentences, the client works well).
A client application with controller.m as follows:
-(void)awakeFromNib
{
NSPort *sendPort=nil;
NSConnection *conn;
sendPort = [[NSMachBootstrapServer sharedInstance]
portForName:@"mytest" host:nil];
if(sendPort == nil)
{
exit(1);
}
conn = [[NSConnection alloc] initWithReceivePort:nil
sendPort:sendPort];
proxyObj = nil;
proxyObj = [[conn rootProxy] retain];
[m_proxyObj setProtocolForProxy:@protocol(ServerProtocol)];
//[conn autoRelease];
}
Is there anything wrong? Should I add [conn autoRelease]; and [proxyObj
release]; in my client application?
Thanks very much for any help!
Fei