Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Exc_bad_access

Exc_bad_access
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 28, 2003, 11:23 PM
 
I am trying to get some Rendezvous sharing working in my program. Things seem to be going okay. I can get the two computers to see each other and register the services and I can even get one computer to send the data to the other and it gets processed properly on the client end. The problem is that the server quits with SIG 11 immediately after closing the connection. I turned on the debugger and it gives me an EXC_BAD_ACCESS message and puts a red hightlight around main:

Code:
int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); }
The last bit of server code to function as far as I can tell is this:

Code:
- (void)connectionReceived:(NSNotification *)aNotification { NSLog(@"connection received"); NSFileHandle * incomingConnection = [[aNotification userInfo] objectForKey:NSFileHandleNotificationFileHandleItem]; NSLog(@"nsfilehandle established"); NSLog(@"machineName=%@,%d,%@,%d,%@",[localMachine machineName],[localMachine progress],[localMachine estimatedTimeOfCompletion],[localMachine secondProgress],[localMachine secondEstimatedTimeOfCompletion]); NSString *serverInfo = [NSString stringWithFormat:@"%@,%d,%@,%d,%@", [localMachine machineName],[localMachine progress],[localMachine estimatedTimeOfCompletion],[localMachine secondProgress],[localMachine secondEstimatedTimeOfCompletion]]; NSLog(@"finished serverinfo"); NSLog(@"serverInfo=%@",serverInfo); NSData *serverInfoData = [NSData dataWithBytes:[serverInfo UTF8String] length:[serverInfo length]]; NSLog(@"NSData made"); [[aNotification object] acceptConnectionInBackgroundAndNotify]; [incomingConnection writeData:serverInfoData]; [incomingConnection closeFile]; [incomingConnection release]; NSLog(@"end connection received"); }
That last NSLog is posted just fine. Any ideas where to look? I'm new to the debugger so I don't really know how to assess its output very well.

thanks,
kman
     
Forum Regular
Join Date: Oct 2001
Status: Offline
Reply With Quote
May 28, 2003, 11:53 PM
 
this page is very helpful, though i have not tried it myself just yet.

http://www.cocoadev.com/index.pl?DebuggingAutorelease
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 29, 2003, 12:14 AM
 
Thank you. I didn't actually have to do what was suggested on that page, but it was a great read and caused me to just remove that release statement at the end of the that method and now it works great.

kman
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
May 29, 2003, 02:21 AM
 
Originally posted by kman42:
Thank you. I didn't actually have to do what was suggested on that page, but it was a great read and caused me to just remove that release statement at the end of the that method and now it works great.
The reason you didn't need to release the NSFileHandle was that you didn't acutally allocate it yourself with the alloc, new, or copy families then you don't need to release it. If you send it a retain however, then you need a corresponding release or autorelease.

For a full discussion of Memory Management and Object Ownership in Cocoa, see Apple's developer documentation, the same file is also in the Developer Tools documentation on your hard disk:
/Developer/Documentation/Cocoa/TasksAndConcepts/ProgrammingTopics/MemoryMgmt/Concepts/ObjectOwnership.html

- proton
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
May 30, 2003, 07:30 PM
 
I had the same problem probably 5 or 6 times before I finally got the hang (sort of) of what to retain and what not to. It caused me no end of pain before I learned about NSZombie.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:36 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2