Skip to content

Instantly share code, notes, and snippets.

@florieger
Created April 11, 2012 14:22
Show Gist options
  • Save florieger/2359613 to your computer and use it in GitHub Desktop.
Save florieger/2359613 to your computer and use it in GitHub Desktop.
Memory Efficient Image Loading
#pragma mark -
#pragma mark Memory Efficient Image Loading
+ (UIImage*)imageWithContentsOfFilename:(NSString*)filename
{
NSMutableString* path = [NSMutableString stringWithString:[[NSBundle mainBundle] bundlePath]];
[path appendString:@"/"];
[path appendString:filename];
return [UIImage imageWithContentsOfFile:path];
}
@florieger
Copy link
Author

Instead of [UIImage imageNamed:@"your.png"] which caches the image data,
this method releases the memory of the image immediately after the UIImage object is deallocated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment