免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 611 | 回复: 0
打印 上一主题 下一主题

About Memory [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:51 |只看该作者 |倒序浏览
  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. */
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP