choise
choise

Reputation: 25254

three20 App crashes after some view changes

first, i followed this tutorial: three20 github tutorial

i have a memory management problem i think, which crashes my application.

i think, _properties in my postsModel crashes my application.

the first time i launch my application and changing view to my postsTableViewController works quite fine. i created a TTLauncherView, changing back to this viewcontroller crashes my app.

here now some code of my postsModel

// .h
@interface postsModel : TTURLRequestModel {
     NSMutableArray *_properties;
}
@property (nonatomic, readonly)NSMutableArray *properties;

// .m
@synthesize properties = _properties;   
- (void)requestDidFinishLoad:(TTURLRequest*)request {
     TTURLDataResponse* response = request.response;
     NSString* responseBody = [[NSString alloc] initWithData: response.data encoding: NSUTF8StringEncoding];

     NSDictionary *json =  [responseBody JSONValue];
     TT_RELEASE_SAFELY(responseBody);

     NSMutableArray *resultSet = [json objectForKey:@"posts"];
     TT_RELEASE_SAFELY(_properties);
     _properties = [NSMutableArray arrayWithArray:resultSet];
     TT_RELEASE_SAFELY(resultSet);

     [super requestDidFinishLoad:request];
}


- (void)dealloc {
     TT_RELEASE_SAFELY(_properties);

     [super dealloc];
}

removing the tt_release of my _properties stops crashing the application by going back from this view to the Launcher view, but clicking on my TableView again, crashes the application again.

its a bit difficult to write down for me, because its quite a lot of code. i can also provide my app as a .zip file if it helps, its very basic right now.

thank

Upvotes: 0

Views: 604

Answers (1)

Stefan Arentz
Stefan Arentz

Reputation: 34945

Yes, the bug is a common one. Change:

_properties = [NSMutableArray arrayWithArray:resultSet];

To:

_properties = [[NSMutableArray arrayWithArray:resultSet] retain];

Or make the property retaining and use:

self.properties = [NSMutableArray arrayWithArray:resultSet];

Upvotes: 2

Related Questions