- 论坛徽章:
- 0
|
- NSString *mm = [[NSString stringWithFormat:@"Minaki"] retain];
-
NSString *gg = [mm copy];
-
printf("mm----> %s gg---->%s \n", [mm UTF8String], [gg UTF8String]);
-
[mm release];
-
mm = [[NSString stringWithFormat:@"Lexi"] retain];
-
printf("mm----> %s gg---->%s \n", [mm UTF8String], [gg UTF8String]);
-
[mm release];
-
[gg release];
-
-
[self.window makeKeyAndVisible];
-
-
-
//对一个对象中的某一个属性retain之后,释放该对象,不会造成内存泄露,如下:
-
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
Model *model = [[Model alloc] init];
-
printf("str:%d \n", [model.str retainCount]);
-
printf("str:%d \n", [model.str retainCount]);
-
model.str = [NSString stringWithFormat:@"String"];
-
printf("str:%d \n", [model.str retainCount]);
-
model.arr = [NSArray arrayWithObjects:@"Array", nil];
-
NSString *str2 = [model.str retain];
-
printf("str:%d \n", [model.str retainCount]);
-
printf("model:%d \n", [model retainCount]);
-
printf("str2:%d \n", [str2 retainCount]);
-
[model release];
-
model = nil;
-
printf("model:%d \n", [model retainCount]);
-
printf("str2:%d \n", [str2 retainCount]);
-
[pool release];
-
printf("str2:%d \n", [str2 retainCount]);
-
[str2 release];
-
/*
-
CGRect *rects = nil;
-
rects = (CGRect *)malloc(sizeof(CGRect) * 3);
-
rects[0] = CGRectMake(0, 0, 10, 10);
-
rects[1] = CGRectMake(1, 1, 10, 10);
-
rects[2] = CGRectMake(2, 2, 10, 10);
-
-
for (int i = 0; i < 3; i++) {
-
CGRect rect = *rects;
-
rects++;
-
NSLog(@"x:%f y:%f width:%f height:%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
-
}
-
*/
|
|