DO, rootProxy, and garbage collection
DO, rootProxy, and garbage collection
- Subject: DO, rootProxy, and garbage collection
- From: John Pannell <email@hidden>
- Date: Thu, 28 Feb 2008 06:16:17 -0700
Hi all-
I have a small existing app that I've chosen to rewrite for my next
release, primarily as an exercise in adopting Leopard and ObjC 2.0
technologies. This includes the use of garbage collection.
Part of this app's design involves the use of distributed objects to
communicate between a server and a couple of client objects. I'm
using NSSocketPorts and communicating between machines. Long story
short: I've encountered memory-related problems with the garbage
collected code, but been able to use the same code successfully
without GC. Specifically, when the client calls rootProxy on its
NSConnection instance, it triggers memory related crashes or
exceptions on the server (i.e. crash with EXC_BAD_ACCESS or "selector
not recognized" exceptions for unrelated objects). I have verified
that the server connection's rootObject is still in place and not
collected when the client calls; it just seems that something in the
DO plumbing does not care for garbage collection. Here's a few snips
of relevant code:
Client - the variables "addressData" and "family" are determined via
Bonjour and NSNetService, and have been confirmed correct...
// create socket port
NSSocketPort *port = [[NSSocketPort alloc]
initRemoteWithProtocolFamily:family socketType:SOCK_STREAM
protocol:IPPROTO_TCP address:addressData];
// create connection
conn = [[NSConnection alloc] initWithReceivePort:nil sendPort:port];
targetServer = (id<PSMServerProtocol, BSGameEngineProtocol>)[conn
rootProxy];
Server - "socketfd" is a BSD socket created and configured properly
(confirmed)
// create NSSocketPort from BSD socket
NSSocketPort *newPort = [[NSSocketPort alloc]
initWithProtocolFamily:PF_INET socketType:SOCK_STREAM
protocol:IPPROTO_TCP socket:socketfd];
// create and configure connection
conn = [[NSConnection alloc] initWithReceivePort:newPort sendPort:nil];
[conn setRootObject:self];
Again, I've confirmed that the expected rootObject set on the server
is still in place when the client calls for the rootProxy. There is
simply something about asking for the rootProxy that causes the server
(somewhere in the DO pipeline) to refer to memory that has been
collected, or at least does not contain the expected object.
Before I give up on adopting GC for this, can anyone comment on
similar experiences or suggest other places to look in the search for
stability? Any help is greatly appreciated!
John
John Pannell
Positive Spin Media
http://www.positivespinmedia.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden