XCode中引入了静态分析器,用于发现普通编译错误以外的错误

选择Build->Build and Analyze

请看下面这段代码

#import <Foundation/FOundation.h>

int main(int agrc, const char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSDate *date = [[NSDate alloc] init];
    NSLog(@"The time is: %@", date);
    
    [pool drain];
    return 0;
}

 

上面这段代码中, date对象在创建后没有被释放

所以, 我们应该加上[date release]

正确的代码

#import <Foundation/FOundation.h>

int main(int agrc, const char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSDate *date = [[NSDate alloc] init];
    NSLog(@"The time is: %@", date);
    [date release];
    [pool drain];
    return 0;
}

 

 

相关文章:

  • 2021-06-02
  • 2021-04-15
  • 2021-08-22
  • 2022-01-24
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2021-09-11
  • 2021-06-20
  • 2022-12-23
  • 2021-12-28
  • 2021-10-15
相关资源
相似解决方案