I have problem with memory. I use ARC. I’ m loading .jpgs to UIImageView on my view.
Code showing example situation:
//.h file
@interface myClass : UIViewController
{
IBOutlet UIImageView * back;
}
// don' t have @property
// back is connected in .xib
//.m file
-(void) viewDidLoad {
UIImage * myImg =[UIImage imageNamed:imgName];
back.image=myImg;
}
-(void) returnToPrevoriousView {
[self removeFromSuperview];
back.image = nil;
}
The problem is that i come to this view from the other view and imgName can have many values. I can come myClass for example six times then I have log: Recieve memory warning and my app crash.
I think myImg isn’ t released from memory? I don’ t have any idea how fix it ? JPGs have about 100kb.
PS. When I load .png it’ s works(aslo faster) in spite of .png images have usually 600kB. But I think it still don’ t release memory ?
Do not use
UIImage imageNamed:if you are certain that the image will not be used again within your app.imageNamed:uses an internal caching mechanism that will use additional memory.From the UIImage Class Reference:
Instead use
UIImage imageWithContentsOfFile:for single use images as those are not cached.Note: only
imageNamed:will do automatic retina version loading (@2x).