I have this code and XCode Analyze does not issue any warnings, but in the console every time I get a message:
2012-07-19 23:15:35.122 AttachIt [5725:907] Received memory warning.
Where is my mistake, point it, please.
for(int j=0;j<images;j++){
@autoreleasepool {
NSInteger currentRow = 0;
for(int k = 0; k<i;k++)
currentRow = currentRow + [[assetGroups objectAtIndex:k] numberOfAssets];
asset = [assets objectAtIndex:j+currentRow];
float size = [self getRandomNumberBetweenMin:60.0 andMax:65.0];
CGRect rect;
if(iPad)
rect = CGRectMake(10+j*35.5, 75-size, size, size);
else
rect = CGRectMake(10+j*26, 75-size, size, size);
UIImageView *temp = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[asset thumbnail]]];
temp.frame = rect;
temp.layer.backgroundColor = [UIColor blueColor].CGColor;
temp.layer.shadowOffset = CGSizeMake(0, 3);
temp.layer.shadowRadius = 5.0;
temp.layer.shadowColor = [UIColor blackColor].CGColor;
temp.layer.shadowOpacity = 0.8;
temp.layer.masksToBounds = NO;
temp.layer.borderColor = [[UIColor whiteColor] CGColor];
temp.layer.borderWidth = 2;
[temp setTransform:CGAffineTransformMakeRotation(degreesToRadians([self getRandomNumberBetweenMin:-5 andMax:5]))];
temp.layer.shouldRasterize = TRUE;
[albumRow addSubview:temp];
}
}
Memory warnings are not the result of mistakes; they are a normal part of running on iOS. You're allocating a bunch of stuff, so getting a memory warning is not surprising.
If you're having problems where your app is being killed by the system due to excess memory usage, you might consider populating those images over time rather than in a loop. You could accomplish this via an NSOperationQueue or similar mechanism to load the images one at a time.
In any case, you could use the "Allocations" or "Activity Monitor" instruments to see if your memory usage is growing and by how much.