I use the following code on an iPhone to get a reduced crop image as follows:
- (UIImage*) getSmallImage:(UIImage*) img { CGSize size = img.size; CGFloat ratio = 0; if (size.width < size.height) { ratio = 36 / size.width; } else { ratio = 36 / size.height; } CGRect rect = CGRectMake(0.0, 0.0, ratio * size.width, ratio * size.height); UIGraphicsBeginImageContext(rect.size); [img drawInRect:rect]; UIImage *tempImg = [UIGraphicsGetImageFromCurrentImageContext() retain]; UIGraphicsEndImageContext(); return [tempImg autorelease]; } - (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect {
I use the following line of code in cellForRowAtIndexPath to update the cell image:
cell.img.image = [self imageByCropping:[self getSmallImage:[UIImage imageNamed:@"goal_image.png"]] toRect:CGRectMake(0, 0, 36, 36)];
Now, when I add this table view and pop it out of the navigation controller, I see a burst with memory. I do not see leaks, but memory continues to rise.
Note that the images change for each row, and I create the controller using the lazy initialization, which I create or highlight when I need it.
I have seen on the Internet a lot of people facing the same problem, but very rare good solutions. I have several views using the same path, and I see that almost the memory has been raised to 4 MB for 20-25 views.
What a good solution to solve this problem.
Tpx.
iphone
rkb
source share