Simple leak not showing in Instruments-Leak tool
Why when the following code (intentionally leaky) is executed with the Instrument-Leaks tool, does it show that there is a leak for NSObject, but not NSDate? They both show up when run with the Analyze static analysis tool as I would expect.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSObject* obj = [NSObj开发者_StackOverflowect alloc];
obj = [NSObject alloc];
NSDate* date = [NSDate alloc];
date = [NSDate alloc];
sleep(10); // time to allow leaks to pick up sample
return 0;
}
This is just a assumption: NSDate could implement some pretty-hard hacks for performance which makes its -alloc method return a cached value.
精彩评论