RE: Releasing Memory when using "TrivialThreads"
RE: Releasing Memory when using "TrivialThreads"
- Subject: RE: Releasing Memory when using "TrivialThreads"
- From: John Nairn <email@hidden>
- Date: Wed, 14 Aug 2002 12:07:43 -0600
I found part of the problem from previous post with this subject.
The main thread in my application is called TextController which gets
connected to RunServer along the lines of Trivial thread. After the
connections are complete, I checked and found the retainCount of
TextController is up to 3. Thus it is probably getting released when the
window is closed by never gets deallocated. The question is how to
handle it correctly:
The connection is made (as in TrivialThreads) when the window loads with
port1=[NSPort port];
port2=[NSPort port];
connectionToRunServer=[[NSConnection alloc]
initWithReceivePort:port1 sendPort:port2];
[connectionToRunServer setRootObject:self];
Does connectionToRunServer retain self? I checked [self retainCount] and
it is 4 after this code; I was expecting 1 or 2.
Next a thread is detached to connectWithPorts: (as in TrivialThreads)
which has code
connectionToController=[NSConnection
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray
objectAtIndex:1]];
serverObject=[[self alloc] init];
[(TextController *)[connectionToController rootProxy]
setServer:serverObject];
[serverObject release];
At this point the TextController retain count has gone down to 2 and
serverObject is 1.
Once the UI gets going, however, TextController has climbed to retain
count of 3 and seems to stay there while the window is open.
I checked Apple SimpleThreads sample code. It has code to release
servers and connections but a comment that the code does not work
correctly and that retain counts are unexpectedly climbing.
So, is it even possible to control memory at the same time you are using
distributed objects or is that part of Cocoa incomplete? Perhaps having
each window (i.e. the WindowController) connect to its own calculation
server (as I need) is not even possible without memory leaks?
----------------
John Nairn (1-801-581-3413, FAX: 1-801-581-4816)
Web page:
http://www.mse.utah.edu/~nairn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.