转自:http://iamnotpg.blogspot.com/2012/08/ios.html
[UIImage imageNamed:ImageName];
NSString *thumbnailFile = [NSString stringWithFormat:@"%@/%@.png", [[NSBundle mainBundle] resourcePath], fileName]; UIImage *thumbnail = [UIImage imageWithContentsOfFile:thumbnailFile];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath]
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }
int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int i, j; for (i = 0; i < 100; i++ ) { NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init]; for (j = 0; j < 100000; j++ ) [NSString stringWithFormat:@"1234567890"];//产生的对象是autorelease的。 [loopPool release]; } [pool release]; return (0); } // main
//测试机器 2.4 GHz Intel Core 2Duo 2GB 667 MHz DDR2 GCC 4.2 - (void)testStringSpeed:(id)sender { NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init]; [textField setStringValue:@""]; int testi,testnum=10; float c,tm=0.0; for(testi=0;testi<testnum;testi++){ NSDate *beg=[NSDate date]; int i,n=10000000; for(i=0;i<n;i++){ //avg=0.030204 /* { //avg=0.594266 内存基本稳定不变 NSString *t=[[NSString alloc] initWithString:@"abccc"]; [t release]; }*/ /* { //avg=0.026101 内存基本稳定不变 NSString *astring = @"abcc"; }*/ /* { //avg=0.278873 内存基本稳定不变 NSString *astring = [[NSString alloc] init]; astring = @"abcc"; [astring release]; }*/ /* { //avg=2.737541 内存基本稳定不变 char *Cstring = "abcc"; NSString *astring = [[NSString alloc] initWithCString:Cstring]; [astring release]; }*/ /* { //avg=3.619728 内存增长过快 NSString *a=[NSString stringWithString:@"abcc"]; }*/ /* { //太长时间,内存增长过快 NSString *a=[NSString stringWithFormat:@"abcc%d",i]; } */ /* { //avg=0.034632 内存基本稳定不变 char a[]="abcc"; }*/ /* { //18.1555 内存稍有增长 NSString *a=[[NSString alloc] initWithFormat:@"abcc%d",i]; [a release]; }*/ /* { //avg=2.276076 内存基本稳定不变 char a[32]; sprintf(a,"abcc%d",i); }*/ /* { //太长时间,内存增长过快 NSMutableString *a=[[NSMutableString alloc] init]; [a stringByAppendingFormat:@"abcc%d",i]; [a release]; }*/ } c=[[NSDate date] timeIntervalSinceDate:beg]; tm+=c; [textField setStringValue:[NSString stringWithFormat:@"%@\n%d=%f",[textField stringValue],testi+1,c]]; } [textField setStringValue:[NSString stringWithFormat:@"%@\navg=%f",[textField stringValue],(float)tm/testnum]]; [pool release]; }
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];