Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management problem in using of NSConnection



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




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.