• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: garbage collection and NSConnection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: garbage collection and NSConnection


  • Subject: Re: garbage collection and NSConnection
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 30 Jun 2008 22:19:08 +0200

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 .



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: garbage collection and NSConnection
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >garbage collection and NSConnection (From: email@hidden)
 >Re: garbage collection and NSConnection (From: eblu <email@hidden>)

  • Prev by Date: Re: garbage collection and NSConnection
  • Next by Date: Splitting an NSAttributedString across different NSRects of a given size
  • Previous by thread: Re: garbage collection and NSConnection
  • Next by thread: Re: garbage collection and NSConnection
  • Index(es):
    • Date
    • Thread