views:

317

answers:

1

hi everybody,

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

+2  A: 

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];
St3fan
has no effect to my crash problem :(
choise
Well, look for similar mistakes in other parts of your code then. This could certainly lead to crashes.
St3fan
is there no way to find the position where my application crashes ? debugger is not really helpful
choise
What do you see in the debugger? What if you enable NSZombieEnabled?
St3fan
thanks! not retaining or using the setter method for my properties object was my main bug. with fixing this, it was easy to find another memory leak i created by releasing a already released object. now its working perfectly.
choise