Chinaunix首页 | 论坛 | 博客
  • 博客访问: 46521
  • 博文数量: 40
  • 博客积分: 825
  • 博客等级: 准尉
  • 技术积分: 365
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-01 10:46
文章分类

全部博文(40)

文章存档

2013年(2)

2012年(15)

2011年(23)

我的朋友

分类: 嵌入式

2011-07-04 16:32:27

  1. NSString *mm = [[NSString stringWithFormat:@"Minaki"] retain];
  2. NSString *gg = [mm copy];
  3. printf("mm----> %s gg---->%s \n", [mm UTF8String], [gg UTF8String]);
  4. [mm release];
  5. mm = [[NSString stringWithFormat:@"Lexi"] retain];
  6. printf("mm----> %s gg---->%s \n", [mm UTF8String], [gg UTF8String]);
  7. [mm release];
  8. [gg release];
  9. [self.window makeKeyAndVisible];
  10. //对一个对象中的某一个属性retain之后,释放该对象,不会造成内存泄露,如下:
  11. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  12. Model *model = [[Model alloc] init];
  13. printf("str:%d \n", [model.str retainCount]);
  14. printf("str:%d \n", [model.str retainCount]);
  15. model.str = [NSString stringWithFormat:@"String"];
  16. printf("str:%d \n", [model.str retainCount]);
  17. model.arr = [NSArray arrayWithObjects:@"Array", nil];
  18. NSString *str2 = [model.str retain];
  19. printf("str:%d \n", [model.str retainCount]);
  20. printf("model:%d \n", [model retainCount]);
  21. printf("str2:%d \n", [str2 retainCount]);
  22. [model release];
  23. model = nil;
  24. printf("model:%d \n", [model retainCount]);
  25. printf("str2:%d \n", [str2 retainCount]);
  26. [pool release];
  27. printf("str2:%d \n", [str2 retainCount]);
  28. [str2 release];
  29. /*
  30. CGRect *rects = nil;
  31. rects = (CGRect *)malloc(sizeof(CGRect) * 3);
  32. rects[0] = CGRectMake(0, 0, 10, 10);
  33. rects[1] = CGRectMake(1, 1, 10, 10);
  34. rects[2] = CGRectMake(2, 2, 10, 10);
  35. for (int i = 0; i < 3; i++) {
  36. CGRect rect = *rects;
  37. rects++;
  38. NSLog(@"x:%f y:%f width:%f height:%f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
  39. }
  40. */
阅读(386) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~