Skip navigation.
 
mlRe: garbage collection and NSConnection
FROM : Jean-Daniel Dupas
DATE : Mon Jun 30 22:25:08 2008

Le 30 juin 08 à 22:19, Jean-Daniel Dupas a écrit :

> Le 30 juin 08 à 22:10, eblu a écrit :
>

>> Hi Chris,
>>     I'm not terribly sure what you are asking for here. From my 
>> experience (limited experience admittedly) theres really only one 
>> way to use NSConnection.
>> its a pretty elegant class, which is simple, and works as expected, 
>> except for when garbage collection is enabled.
>>
>> heres what I do just after NSNetService finds a service:
>>
>> // Sent when a service appears
>> - (void)netServiceBrowser:(NSNetServiceBrowser *)browser
>>      didFindService:(NSNetService *)aNetService
>>      moreComing:(BOOL)moreComing
>> {
>>     NSMutableDictionary* newDict = [[NSMutableDictionary alloc] init];
>>     [newDict setValue:aNetService forKey:@"theService"];
>>     
>>     [serverArrayController addObject:newDict];
>>     [aNetService setDelegate:self];
>>     [aNetService resolveWithTimeout:5];
>>  if(!moreComing)
>>  {
>>  }
>> }
>>
>> // NSNetService Delegate method:
>> - (void)netServiceDidResolveAddress:(NSNetService *)sender{
>>     
>>     id proxy = nil;
>>     NSData *addy;
>>     NSSocketPort* socket;
>>     NSConnection* connection;
>>     NSString* hostname;
>>     
>>     int a;
>>     int i;
>>     
>>     hostname = [sender hostName];
>>     socket = (NSSocketPort*)[[NSSocketPortNameServer sharedInstance] 
>> portForName:@"BKOtherPort" host:hostname];
>>     connection = [NSConnection connectionWithReceivePort: nil 
>> sendPort: socket];
>>     @try{
>>         proxy = [connection rootProxy];
>>     }
>>     @catch(id exception){
>>         proxy = nil;
>>
>>     }
>>     addy = [socket address];
>>     if(proxy){
>>             // app level stuff if the proxy exists
>>     }
>> }
>>
>> pretty straight forward,
>> and every time I ran it with garbage collection on, the 
>> NSConnection initialized, but NEVER returned the proxy. it returned 
>> nil.
>> all my instance variables were populated, everything on My end was 
>> correct... or at least behaving as expected. it just wouldn't 
>> return the proxy object (or the root for that matter)
>> All I did to fix it, was to turn off garbage collection.
>> That part runs like a champ now.  the rest of the app won't do 
>> anything anymore, as it was built on garbage collection.
>>
>> cheers,
>> -eb
>>

>
> And did you try using CFNetServices instead ? As it is CF based, it 
> probably does not have the same GC problem and is it far more easier 
> to replace NSNetService by CFNetService than rewriting the whole 
> application without GC .


Sorry, it the DO part that does not works, not the Bonjour discovery. 
I read it a little to fast.

Related mailsAuthorDate
mlgarbage collection and NSConnection eblugamma Jun 30, 19:33
mlRe: garbage collection and NSConnection John Pannell Jun 30, 20:57
mlRe: garbage collection and NSConnection eblu Jun 30, 22:10
mlRe: garbage collection and NSConnection Jean-Daniel Dupas Jun 30, 22:19
mlRe: garbage collection and NSConnection Jean-Daniel Dupas Jun 30, 22:25
mlRe: garbage collection and NSConnection Hamish Allan Jun 30, 23:23
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 3, 00:09
mlRe: garbage collection and NSConnection Michael Ash Jul 3, 03:33
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 4, 11:25
mlRe: garbage collection and NSConnection Jean-Daniel Dupas Jul 4, 11:38
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 4, 18:32
mlRe: garbage collection and NSConnection Chris Hanson Jul 4, 22:54
mlRe: garbage collection and NSConnection Chris Hanson Jul 4, 23:02
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 6, 00:00
mlRe: garbage collection and NSConnection mmalc crawford Jul 6, 02:05
mlRe: garbage collection and NSConnection Bill Bumgarner Jul 6, 02:09
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 6, 08:47
mlRe: garbage collection and NSConnection Hamish Allan Jul 7, 00:18
mlRe: garbage collection and NSConnection Joan Lluch (casa) Jul 7, 09:17
mlRe: garbage collection and NSConnection Sean McBride Jul 7, 19:33
mlRe: garbage collection and NSConnection Hamish Allan Jul 8, 00:25
mlRe: garbage collection and NSConnection Marcel Weiher Jul 10, 18:17
mlRe: garbage collection and NSConnection Michael Ash Jul 10, 18:50
mlRe: garbage collection and NSConnection Marcel Weiher Jul 11, 01:33
mlRe: garbage collection and NSConnection Michael Ash Jul 11, 05:29
mlRe: garbage collection and NSConnection Marcel Weiher Jul 11, 09:21
mlRe: garbage collection and NSConnection Michael Ash Jul 11, 17:59
mlRe: garbage collection and NSConnection Marcel Weiher Jul 11, 20:17
mlRe: garbage collection and NSConnection Michael Ash Jul 11, 21:53
mlRe: garbage collection and NSConnection Sean McBride Jul 12, 00:19
mlRe: garbage collection and NSConnection Marcel Weiher Jul 12, 08:25
mlRe: garbage collection and NSConnection Michael Ash Jul 12, 17:25
mlRe: garbage collection and NSConnection Marcel Weiher Jul 12, 19:24
mlRe: garbage collection and NSConnection Gary L. Wade Jul 12, 21:33
mlRe: garbage collection and NSConnection Michael Ash Jul 12, 22:42
mlRe: garbage collection and NSConnection Gary L. Wade Jul 12, 23:36
mlRe: garbage collection and NSConnection Marcel Weiher Jul 13, 18:29
mlRe: garbage collection and NSConnection Michael Ash Jul 13, 22:19