1

I do webservice requests with a UISegmentedControl, when I change segmentedItem and request fast the application crashes with this message:

[Session started at 2011-05-12 10:58:50 +0200.] Terminating in response to SpringBoard's termination.

[Session started at 2011-05-12 11:06:31 +0200.] GNU gdb 6.3.50-20050815 (Apple version gdb-1516) (Fri Feb 11 06:19:43 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001 Loading program into debugger… Program loaded. target remote-mobile /tmp/.XcodeGDBRemote-239-58 Switching to remote-macosx protocol mem 0x1000 0x3fffffff cache mem 0x40000000 0xffffffff none mem 0x00000000 0x0fff none run Running… [Switching to thread 11779] [Switching to thread 11779] sharedlibrary apply-load-rules all continue Program received signal: “SIGKILL”. warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). kill quit

The Debugger has exited with status 0.(gdb)

Does anybody have an idea of how can I fix this? Is this a problem because I'm not using NSOperationQueue? And if so any suggestions how I can fix this would be very welcomed. I can not find any memory leaks when running.

Next time I ran it this message got logged:

Program received signal: “EXC_BAD_ACCESS”. warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found). (gdb)

Here is the code for starting the connection:

Class header ServiceGetChildren:

#import <Foundation/Foundation.h>

@class Authentication;
@class AttendanceReportViewController;

@interface ServiceGetChildren : NSObject {

Authentication *authentication;
AttendanceReportViewController *attendanceReportViewController;

NSString *username;
NSString *password;
NSMutableString *authenticationString;
NSString *encodedLoginData;
NSMutableData *responseData;
NSMutableArray *childrensArray;
}

@property (nonatomic, retain) NSString *username;
@property (nonatomic, retain) NSString *password;
@property (nonatomic, retain) NSMutableString *authenticationString;
@property (nonatomic, retain) NSString *encodedLoginData;
@property (nonatomic, retain) NSMutableData *responseData;
@property (nonatomic, retain) NSMutableArray *childrensArray;

- (void)startService:(NSURL *)url :(NSString *)method withParent:(UIViewController *)controller;

@end

Class handling the request:

#import "ServiceGetChildren.h"
#import "JSON.h"
#import "Base64.h"
#import "AttendanceReportViewController.h"
#import "Authentication.h"

@implementation ServiceGetChildren

@synthesize appDelegate;

@synthesize username;
@synthesize password;
@synthesize authenticationString;
@synthesize encodedLoginData;
@synthesize responseData;
@synthesize childrensArray;

- (id) init {

if ((self = [super init])) {

}
return self;
}

- (void)startService:(NSURL *)url :(NSString *)method withParent:(UIViewController *)controller {

username = appDelegate.username;
password = appDelegate.password;

attendanceReportViewController = (AttendanceReportViewController *)controller;

Authentication *auth = [[Authentication alloc] init];
authenticationString = (NSMutableString*)[@"" stringByAppendingFormat:@"%@:%@", username, password];    
encodedLoginData = [auth encodedAuthentication:authenticationString];
[auth release];

// Setup up the request with the url
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url
                                                       cachePolicy: NSURLRequestReloadIgnoringCacheData 
                                                   timeoutInterval: 20.0];   
[request setHTTPMethod:method];
[request setValue:[NSString stringWithFormat:@"Basic %@", encodedLoginData] forHTTPHeaderField:@"Authorization"];

NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];

// Display the network indicator when the connection request started
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

// Check that the NSURLConnection was successful and then initialize the responseData
if(connection) {
    NSLog(@"Connection made");
    responseData = [[NSMutableData data] retain];
}
else {
    NSLog(@"Connection could not be made");
}
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {


[responseData setLength:0];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

[responseData appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

NSLog(@"Connection finished loading.");  
// Dismiss the network indicator when connection finished loading
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

// Parse the responseData of json objects retrieved from the service
SBJSON *parser = [[SBJSON alloc] init];

NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *jsonData = [parser objectWithString:jsonString error:nil];
NSMutableArray *array = [jsonData objectForKey:@"Children"];

childrensArray = [NSMutableArray arrayWithArray:array];

// Callback to AttendanceReportViewController that the responseData finished loading
[attendanceReportViewController loadChildren];

[connection release];
[responseData release];
[jsonString release];
[parser release];
}

 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failure.");
NSLog(@"ERROR%@", error);
// Dismiss the network indicator when connection failure occurred
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[connection release];
// Inform the user that the server was unavailable
}

- (void) dealloc {

[attendanceReportViewController release];
[super dealloc];
}

Class header for AttendanceReportViewController:

#import <UIKit/UIKit.h>

@class ServiceGetGroups;
@class ServiceGetChildren;
@class DetailViewController;

@interface AttendanceReportViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {

ServiceGetGroups *serviceGetGroups;
ServiceGetChildren *serviceGetChildren;
DetailViewController *detailViewController;

UISegmentedControl *segmentedControl;
IBOutlet UIToolbar *groupsToolbar;
NSMutableArray *btnArray;
NSInteger index;

IBOutlet UITableView *theTableView;
IBOutlet UILabel *attendanceLabel;
IBOutlet UILabel *abscentLabel;
IBOutlet UILabel *totalLabel;

NSMutableDictionary *selectRequestDictionary;
NSMutableDictionary *selectNameDictionary;

NSMutableArray *groupsArray;
NSMutableArray *childrensArray;
NSDictionary *childrensDictionary;

NSURL *url;
}

@property (nonatomic, retain) ServiceGetGroups *serviceGetGroups;
@property (nonatomic, retain) ServiceGetChildren *serviceGetChildren;
@property (nonatomic, retain) DetailViewController *detailViewController;

@property (nonatomic, retain) IBOutlet UIToolbar *groupsToolbar;
@property (nonatomic, retain) IBOutlet UITableView *theTableView;
@property (nonatomic, retain) IBOutlet UILabel *attendanceLabel;
@property (nonatomic, retain) IBOutlet UILabel *abscentLabel;
@property (nonatomic, retain) IBOutlet UILabel *totalLabel;
@property (nonatomic, retain) UISegmentedControl *segmentedControl;
@property (nonatomic) NSInteger index;

@property (nonatomic, retain) NSMutableArray *btnArray;
@property (nonatomic, retain) NSMutableDictionary *selectRequestDictionary;
@property (nonatomic, retain) NSMutableDictionary *selectNameDictionary;

@property (nonatomic, retain) NSMutableArray *groupsArray;
@property (nonatomic, retain) NSMutableArray *childrensArray;
@property (nonatomic, retain) NSDictionary *childrensDictionary;

@property (nonatomic, retain) NSURL *url;

- (void)setupSegmentedControl;

- (void)requestGroups;

- (void)requestChildren:(NSNumber *)groupId;

- (void)loadGroups;

- (void)loadChildren;

@end

Class that the Uses the UISegmentedControl:

#import "JSON.h"
#import "AttendanceReportViewController.h"
#import "CustomCellViewController.h"
#import "DetailViewController.h"
#import "ServiceGetGroups.h"
#import "ServiceGetChildren.h"
#import "Group.h"
#import "Child.h"

@implementation AttendanceReportViewController

@synthesize serviceGetGroups;
@synthesize serviceGetChildren;
@synthesize detailViewController;

@synthesize segmentedControl;
@synthesize groupsToolbar;
@synthesize index;
@synthesize btnArray;

@synthesize theTableView;
@synthesize attendanceLabel;
@synthesize abscentLabel;
@synthesize totalLabel;

@synthesize selectRequestDictionary;
@synthesize selectNameDictionary;

@synthesize groupsArray;
@synthesize childrensArray;
@synthesize childrensDictionary;

@synthesize url;
#pragma mark -
#pragma mark View lifecycle

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization.
}
return self;
 }

- (void)requestGroups {

NSURL *groupsURL = [NSURL URLWithString:@"http://services/groups"];
[serviceGetGroups startService:groupsURL :@"GET" withParent:self];  
}

- (void)requestChildren:(NSNumber *)groupId {
NSLog(@"%@", groupId);

NSString *baseURL = @"http://services/group/";
NSString *method = [NSString stringWithFormat:@"%@%@", groupId, @"/children"];
NSString *theURL = [NSString stringWithFormat:@"%@%@", baseURL, method];

self.url = [NSURL URLWithString:theURL];

NSLog(@"%@", self.url);

[serviceGetChildren startService:self.url :@"GET" withParent:self];
 }

- (void)loadGroups {
// Retrieve a array with dictionaries of groups from ServiceGetGroups
self.groupsArray = [[serviceGetGroups.groupsArray copy] autorelease];

// The array to hold segmentedItems for the segmentedControl, representing groups buttons
btnArray = [NSMutableArray arrayWithObjects: @"Alla", nil];

for (NSDictionary *groupDict in groupsArray) {
    // Add each groups name to the btnArray as segmentedItems for the segmentedControl
    [btnArray addObject:[groupDict objectForKey:@"Name"]];  
}

// Create a new NSMutableDictionary with group names as keys and group id´s as values 
// used for reference to segementedControl items to make request to serviceGetChildren
self.selectRequestDictionary = [NSMutableDictionary dictionary];
for (NSDictionary *dict in groupsArray) {
    [selectRequestDictionary setObject:[dict objectForKey:@"Id"] forKey:[dict objectForKey:@"Name"]];
}

// Create a new NSMutableDictionary with group id´s as keys and group names as values 
// used for retrieving a groupName from a passed id
self.selectNameDictionary = [NSMutableDictionary dictionary];
for (NSDictionary *dict in groupsArray) {
    [selectNameDictionary setObject:[dict objectForKey:@"Name"] forKey:[dict objectForKey:@"Id"]];
}

[self setupSegmentedControl];
 }

 - (void)setupSegmentedControl {

// Setup the UISegmentedControl as groups buttons
segmentedControl = nil;

segmentedControl = [[UISegmentedControl alloc] initWithItems:btnArray];
segmentedControl.tintColor = [UIColor darkGrayColor];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 300, 30);

// Setup the target and actions for the segmentedControl
[segmentedControl addTarget:self 
                     action:@selector(selectGroup:) 
           forControlEvents:UIControlEventValueChanged];

// Add the UISegmentedControl as a UIBarButtonItem subview to the UIToolbar
UIBarButtonItem *segmentedItem = [[[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *groupsButtons = [NSArray arrayWithObjects:flexSpace, segmentedItem, flexSpace, nil];
[groupsToolbar setItems:groupsButtons];

[flexSpace release];
}

- (void)loadChildren {

// Retrieve a array with dictionaries of children from ServiceGetChildren
self.childrensArray = [[serviceGetChildren.childrensArray copy] autorelease];   

// TODO create seperate method - Setup compilation bar values
int total = [childrensArray count];
totalLabel.text = [NSString stringWithFormat:@"%d", total]; 

[theTableView reloadData];
}   

// Handles UIControlEventValueChanged for UISegmentedControl, retreives the name and id for a selected group
- (void)selectGroup:(UISegmentedControl *)theSegmentedControl {

NSString *selectedGroup = [segmentedControl titleForSegmentAtIndex: [segmentedControl selectedSegmentIndex]];

NSNumber *selectedId = [selectRequestDictionary objectForKey:selectedGroup];

// Persist the selectedSegmentIndex when view switches to detaildView
index = [segmentedControl selectedSegmentIndex];

// Request children based on the selected groupId
[self requestChildren:selectedId];
}

- (void)viewDidLoad {

[self requestGroups];

[super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.

return [childrensArray count];
 }

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CustomCell";

// Load from nib
CustomCellViewController *cell = (CustomCellViewController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle]
                                loadNibNamed:@"CustomCellView" 
                                owner:nil 
                                options:nil];

    for (id currentObject in topLevelObjects) {
        if ([currentObject isKindOfClass:[UITableViewCell class]]) {
            cell = (CustomCellViewController *) currentObject;
            break;
        }
    }
}
// Set up a children dictionary for easy retrieving specific values to display in the UITableView
childrensDictionary = [childrensArray objectAtIndex:indexPath.row]; 

NSNumber *idForName = [childrensDictionary valueForKey:@"GroupId"];

NSString *name = [NSString stringWithFormat:@"%@ %@", 
                              [childrensDictionary valueForKey:@"Firstname"], 
                              [childrensDictionary valueForKey:@"Surname"]];

NSString *group = [NSString stringWithFormat:@"%@", 
                   [selectNameDictionary objectForKey:idForName]];

cell.childNameLabel.text = name;    
cell.groupNameLabel.text = group;
cell.scheduleLabel.text = @"Schema";
cell.deviationLabel.text = @"Avvikelse";

return cell;
 }

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push the detailedViewController.

if (detailViewController == nil) {
    DetailViewController *_detailViewcontroller = [[DetailViewController alloc]
                                                                       initWithNibName:@"DetailView" bundle:nil];
    self.detailViewController = _detailViewcontroller;
    [_detailViewcontroller release];
}
childrensDictionary = [childrensArray objectAtIndex:indexPath.row];

NSNumber *idForName = [childrensDictionary valueForKey:@"GroupId"];

NSString *group = [NSString stringWithFormat:@"%@", 
                   [selectNameDictionary objectForKey:idForName]];

[self.detailViewController initWithDetailsSelected:childrensDictionary:group];

[self.navigationController pushViewController:detailViewController animated:YES];
}

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Relinquish ownership any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
segmentedControl = nil;
}


- (void)dealloc {

[segmentedControl release];
[groupsArray release];
[childrensArray release];
[detailViewController release];

[super dealloc];
}


@end
Silversnail
  • 386
  • 1
  • 6
  • 23
  • [Enable NSZombie](http://cocoa-nut.de/?p=16) for your active executable and see if the console output shows something new. Try to get the EXC_BAD_ACCESS again. – Nick Weaver May 12 '11 at 09:28
  • I cannot post the picture from allocation tool but each time I push a SegmentedItem 13 categories gets increased by 1mb. – Silversnail May 12 '11 at 09:46
  • OK there we have a clue. I think you should post code in which you create your connection and the part where setLength: is sent. – Nick Weaver May 12 '11 at 09:52
  • How can i find the part where setLength: is sent? – Silversnail May 12 '11 at 12:31
  • Can you set a breakpoint at `[responseData appendData:data];` and step over it and see if it crashes there? – Nick Weaver May 12 '11 at 12:41
  • It doesn´t crash but gets hit every time i push a segmentedItem. variable data has summary 136bytes first push, then second push, the varible is red and value is 2000bytes. If I step over it – Silversnail May 12 '11 at 13:10
  • It does hang when I set breakpoint at **[responseData setLength:0];** and UI gets unresponsive. – Silversnail May 12 '11 at 13:21
  • **responseData = [[NSMutableData data] retain];** is causing the error message **-[NSConcreteMutableData setLength:]: message sent to deallocated instance 0xa5c8f90** If move it to the init method it hangs on first change request. Any idea how I can deal with this? – Silversnail May 12 '11 at 13:54
  • Looks all good, I think the bigger picture is the problem. You call this method when you switch the segment, right? In which class is this code? You should reset your previous connection if it's already doing something. See, you are releasing the connection only when it fails or finishes. Maybe you can outline the class a lil bit more? – Nick Weaver May 12 '11 at 14:16
  • @Nick thanks alot that you take some time to help me, I have struggled with this so long now. I have now put the class that uses the connection above. – Silversnail May 12 '11 at 14:39
  • Alright, can you post the class header where `- (void)startService:(NSURL *)url :(NSString *)method withParent:(UIViewController *)controller` is inside? – Nick Weaver May 12 '11 at 14:46
  • Do you think I have to look into threading? And pass the request somehow on individual threads? – Silversnail May 12 '11 at 15:04
  • Ok, thanks a lot :) posted the other header file to. – Silversnail May 12 '11 at 15:15
  • Here you go, have a look at the answer and try to alter your code. Hope it'll work. However give me some comment on the answer if anything doesn't work out. – Nick Weaver May 12 '11 at 15:28

1 Answers1

4

OK here we go. First of all, I could not test the code, so I need your feedback.

The main problem with this class is, you only have one instance, which you reuse every time you hit the segmented control. This leads to creation of new instances of the NSURLConnection. So let's correct a bit in the header. I changed the NSString properties to copy. Have a look at this Q&A to know why, however this is not important for the improvement, just wanted to let you know.

  • I've removed Authentication *authentication; looked like you don't use it.
  • Added NSURLConnection as property so we keep a reference on it.

Header file

@class Authentication;
@class AttendanceReportViewController;

@interface ServiceGetChildren : NSObject {

    AttendanceReportViewController *attendanceReportViewController;

    NSString *username;
    NSString *password;
    NSMutableString *authenticationString;
    NSString *encodedLoginData;
    NSMutableData *responseData;
    NSMutableArray *childrensArray;
    NSURLConnection *connection;
}

@property (nonatomic, copy) NSString *username;
@property (nonatomic, copy) NSString *password;
@property (nonatomic, retain) NSMutableString *authenticationString;
@property (nonatomic, copy) NSString *encodedLoginData;
@property (nonatomic, retain) NSMutableData *responseData;
@property (nonatomic, retain) NSMutableArray *childrensArray;
@property (nonatomic, retain) NSURLConnection *connection

- (void)startService:(NSURL *)url :(NSString *)method withParent:(UIViewController *)controller;

@end

Next comes the Implementation file. I only altered the startService method and dealloc.

  • If you declare properties, use them :) Have a look at this Q&A for some explanations on synthesized properties.
  • Always release what you own, so I added release code in the dealloc.
  • Cancel the previous request!!! If there is none, the message is sent to nil, which causes no harm.

Implementation file

- (void)startService:(NSURL *)url:(NSString *)method withParent:(UIViewController *)controller
{
    self.username = appDelegate.username;
    self.password = appDelegate.password;

    [connection cancel];

    attendanceReportViewController = (AttendanceReportViewController *)controller;

    Authentication *auth = [[Authentication alloc] init];
    authenticationString = (NSMutableString *)[@"" stringByAppendingFormat:@"%@:%@", username, password];
    self.encodedLoginData = [auth encodedAuthentication:authenticationString];
    [auth release];

    // Setup up the request with the url
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                   cachePolicy:NSURLRequestReloadIgnoringCacheData
                               timeoutInterval:20.0];
    [request setHTTPMethod:method];
    [request setValue:[NSString stringWithFormat:@"Basic %@", encodedLoginData] forHTTPHeaderField:@"Authorization"];

    self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];

    // Display the network indicator when the connection request started
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

    // Check that the NSURLConnection was successful and then initialize the responseData
    if (connection) {
        NSLog(@"Connection made");
        self.responseData = [NSMutableData data];
    } else   {
        NSLog(@"Connection could not be made");
    }
}

...

- (void) dealloc
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    [connection cancel];
    [connection release];

    [appDelegate release];
    [responseData release];
    [username release];
    [password release];
    [authenticationString release];
    [encodedLoginData release];
    [responseData release];
    [childrensArray release];

    [super dealloc];
}

Hope this helps for the next steps. However I think we will have to work a bit on the solution until it's final.

Community
  • 1
  • 1
Nick Weaver
  • 47,228
  • 12
  • 98
  • 108
  • @Nick, Thanks so much! I can not get it to crash anymore! I could not thank you enough for taking the time to help me out! – Silversnail May 12 '11 at 16:03
  • I do still think there is some other performance issues left for me to look into, when I run allocation instrument, I see that everytime I push a segmentedItem: Malloc 1.00kb, Malloc 4.0kb, Malloc 8.0kb, Malloc 2.00kb, Malloc 6.00kb, Malloc 96bytes, Malloc 5.50kb, CFString, CFString(store), CGColorTransform, CGColorTransFormCache, all increments for every click, from between 1.19mb to 4.36mb. Wich raises the overall allocated bytes to 46mb quite fast. – Silversnail May 12 '11 at 16:08
  • So I guess I have some more memory management to look into. I have no clue what it could be. But this time could it be in the ViewController perhaps. – Silversnail May 12 '11 at 16:09
  • I dont want bother you to much because of taking your time already, but perhaps anyone that sees this could give me a hint. The problem I also have is that the first segementedControl segment is a "Everyone", that is it needs to make all the request as each of the other segments do individual. This segment will be selected as default. For this issue do I have to look at NSOperationQueue? All suggestions are welcomed. – Silversnail May 12 '11 at 16:31
  • You are welcome, however I am off for today. I'll get back to you tomorrow and try to find a solution. – Nick Weaver May 12 '11 at 16:51
  • @Nick Great, I will keep looking into this problem tonight, and post it here if I make any progress. Thanks =) – Silversnail May 12 '11 at 17:01
  • Found a problem that this **self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];** and this **self.responseData = [NSMutableData data];** terminates with following output. **-[NSURLConnection cancel]: message sent to deallocated instance 0x4d4faf0 and **-[NSConcreteMutableData release]: message sent to deallocated instance 0x4d57a50** If I remove autorelease on the connection and keep retain on responseData the app runs fine except for a lot of memory leaks related to CFNetwork and NSURLConnection. – Silversnail May 12 '11 at 22:28
  • 1
    Ok if I remove **[connection release];** from connectionDidFinishedLaunching makes the autorelease ok. And also by removing **[responseData release];** from same method. So the it doesn´t leak memoery anymore. – Silversnail May 13 '11 at 12:35
  • Do I set both to nil in the method instead? Like **self.connection = nil;** and **self.responseData = nil;** – Silversnail May 13 '11 at 12:59
  • @Silversnail Yes release the connection and the responseData in the dealloc only. Set it to nil in the `startService` method. Setting the property with `self.XXX = YYY` does two things: it releases the old value(if there is one) and retains the new one. Setting it to nil is a good way to release the current reference and assign nil to it. – Nick Weaver May 13 '11 at 17:51