A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 为梦想挺身而出 中级黑马   /  2014-5-7 19:49  /  1263 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 为梦想挺身而出 于 2014-7-18 11:23 编辑

  1. #import <Foundation/Foundation.h>

  2. int main()
  3. {

  4.     int age = 10;
  5.     int no = 5;
  6.    
  7.   
  8.    
  9.   
  10.     NSString *newStr = [NSString stringWithFormat:@"My age is %d and no is //%d", age,no];
  11.    
  12.     NSLog(@"---%@", newStr);
  13.     return 0;
  14. }
复制代码

终端显示
leskymatoMacBook:04-开发技巧 lesky$ ./a.out
objc[821]: Object 0x1024144f0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
2014-05-07 19:47:44.672 a.out[821:707] ---My age is 10 and no is //5
leskymatoMacBook:04-开发技巧 lesky$
求解 我的终端怎么了

评分

参与人数 1技术分 +1 收起 理由
bao9107 + 1

查看全部评分

6 个回复

倒序浏览
哦这个是提示你没有写自动释放池的代码,估计你是用了非arc,然后类方法出来的NSString方法创建出啦的对象后面自动加上autoRelease。
所以修改方式是你把main函数内的所有代码写在这里面就对了
  1. @autoreleasepool {
  2.        //这里写代码
  3.     }
复制代码

评分

参与人数 1技术分 +1 收起 理由
bao9107 + 1

查看全部评分

回复 使用道具 举报
D调的沉默 发表于 2014-5-7 22:35
哦这个是提示你没有写自动释放池的代码,估计你是用了非arc,然后类方法出来的NSString方法创建出啦的对象 ...

没看明白,能给我写全吗?
回复 使用道具 举报

  1. #import <Foundation/Foundation.h>

  2. int main()
  3. {  
  4.     int age = 10;
  5.     int no = 5;
  6.    
  7.     NSString *name = @"www";
  8.    
  9. //        int size = [name length];
  10. //        NSLog(@"%d", size);

  11.    
  12.     NSString *newStr = [NSString stringWithFormat:@"My age is %d and no is %d,名字是%@", age,no, name];
  13.    
  14.    
  15.     NSLog(@"---%@", newStr);
  16.     return 0;
  17. }
复制代码

我注释的这两行,只要不注释就不会出现终端的问题,求解
回复 使用道具 举报
为梦想挺身而出 发表于 2014-5-7 22:52
没看明白,能给我写全吗?

好把,这么写的

  1. #import <Foundation/Foundation.h>

  2. int main()
  3. {
  4. @autoreleasepool {
  5.    int age = 10;
  6.     int no = 5;
  7.    
  8.    
  9.   
  10.     NSString *newStr = [NSString stringWithFormat:@"My age is %d and no is //%d", age,no];
  11.    
  12.     NSLog(@"---%@", newStr);
  13.     return 0;
  14.       
  15.     }

  16. }
复制代码

你看我这样写,你再运行可会出错?!
回复 使用道具 举报
D调的沉默 发表于 2014-5-7 22:54
好把,这么写的
你看我这样写,你再运行可会出错?!

不会出错了,谢谢!那个return 0; 写在autoreleasepool 大括号里面也行啊
回复 使用道具 举报
为梦想挺身而出 发表于 2014-5-7 23:12
不会出错了,谢谢!那个return 0; 写在autoreleasepool 大括号里面也行啊

里外都是0,它不是对象没什么影响的。。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马