Hi basically I am using the code below to retrieve and store my photos. Every time I click 'load more', the array basically grows (with 10 photo objects more each time). Is there a way to control memory usage for this case? In fact I am only storing the profile image and not the actual sized photos (only URL stored)
- (void)preloadPhotoData
{
self.returnCount = 0;
UIDevice *myDevice = [UIDevice currentDevice];
NSString *deviceUDID = [myDevice uniqueIdentifier];
self.urlString = [NSString stringWithFormat:@"http://myURL.com/photos.json?device_id=%@&page=%i&per_page=%i&type= %@",deviceUDID,self.pageNum,kPhotosPerPage,self.ty pe];
NSString *loadingString = [NSString stringWithFormat:@"Loading data from Instahotness....."];
self.loadingPage.loadingTextLabel.text = loadingString;
[self fetchJSONFile];
}
-(void)fetchJSONFile
{
NSURL *url = [NSURL URLWithString:self.urlString];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
// Use when fetching text data
NSString *responseString = [request responseString];
NSError *error;
SBJsonParser *json = [[SBJsonParser new]autorelease];
self.jsonArray = [json objectWithString:responseString error:&error];
if (self.jsonArray == nil)
{
NSString *errorString = [NSString stringWithFormat:@"JSON parsing failed: %@", [error localizedDescription]];
NSLog(@"%@",errorString);
[self errorHanding];
}
else
{
NSString *createPhotoString = [NSString stringWithFormat:@"Loading Profile Pictures....."];
self.loadingPage.loadingTextLabel.text = createPhotoString;
[self createPhotoArray];
}
}];
[request setFailedBlock:^{
NSError *error = [request error];
NSString *connectionErrString = [NSString stringWithFormat:@"Error Loading Profile Pic: %@", [error description]];
NSLog(@"%@",connectionErrString);
[self errorHanding];
}];
[request startAsynchronous];
}
-(void)createPhotoArray
{
for (int i =0; i<[self.jsonArray count]; i++)
{
NSDictionary *aPhoto = [self.jsonArray objectAtIndex:i];
NSString *pid = [aPhoto valueForKey:@"pid"];
NSString *userName = [aPhoto valueForKey:@"user_username"];
NSString *userFullName = [aPhoto valueForKey:@"user_full_name"];
NSString *userBio = [aPhoto valueForKey:@"user_bio"];
NSString *caption = [aPhoto valueForKey:@"caption"];
NSString *profileImageURL = [aPhoto valueForKey:@"user_profile_picture"];
NSString *standardPhotoURL = [aPhoto valueForKey:@"standard_resolution"];
NSString *isStarred = [aPhoto valueForKey:@"photoIsStarred"];
NSString *thisStarCount = [aPhoto valueForKey:@"star_count"];
BOOL photoIsStarred = [isStarred boolValue];
NSUInteger starCount = [thisStarCount intValue];
Photo *newPhoto = [[[Photo alloc]initWithPid

id
UserName:userName
userBio:userBio
userFullName:userFullName
caption:caption
profileImageURL

rofileImageURL
profileImage:nil
profilePicSize:CGSizeZero
image:standardPhotoURL
imageSize:CGSizeZero
photoIsStarred

hotoIsStarred
starCount:starCount]autorelease];
[self.photoArray addObject:newPhoto];
}
[self fetchPhotoImage];
}