Help with code snippet - memory warning with level 1
Hi guys,
I would like to ask for you opinion on the following code. There are two methods (the first one makes a request for data, and the second one process them). In the app itself it looks like this - on load, app gets the first set of xml data (20 items) that displays in uitableview. At the end 'load more' button appears which brings another set etc.. I have tested cellForRowAtIndexPath method first (by returning an empty cell) just to see if the memory warning will be produced and it does, meaning the cause is probably in one of these two methods.
So i get "Received memory warning. Level=1" after i load 22 pages (thats 22 x 20 = 440 xml items that I hold in my NSMutableArray)
Code:
-(void) loadApps:(NSString *)passedMode withPage:(NSInteger)passedPage showActivityIndicator:(BOOL)showIndicator
{
// showIndicator is YES only for the first time, when the app initially loads the first set of data
if (showIndicator)
[self showActivityIndicator];
useActivityIndicator = showIndicator;
page = passedPage;
[mode setString:passedMode];
// Create the request.
NSMutableString *apiUrl = [[NSMutableString alloc] initWithFormat:@"%@?mode=newest", [AppSettings getServiceUrl]];
[apiUrl appendFormat:@"&page=%d",passedPage];
[apiUrl appendFormat:@"&view=%@",mode];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:apiUrl]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[UrlRequestManager addHeaders:theRequest];
[apiUrl release];
// create the connection with the request
// and start loading the data
serviceCallInProgress = YES;
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
NSMutableData *md = [[NSMutableData alloc] init];
[self setReceivedData:md];
[md release];
}
[theConnection release];
}