I have a very strange issue with the xCode 4.3 memory leak instruments... Basically it does not work in the following case...
- Project is created without ARC support.
- Create a simple class which inherits UIView
- use a "button" to create instance of this class and "leak" it... the leak will not be catch by Leak Instruments
so here is the code of the PROBLEMATIC class
@interface LeakTestView : UIView
- (id)initWithFrame:(CGRect)frame;
@end
@implementation LeakTestView
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"initWithFrame called");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
And now I create the leak...
- (IBAction)leak:(id)sender {
LeakTestView* leak=[[LeakTestView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
NSLog(@"class is %@", [leak class]);
}
So the problem is that this leak will not be detected...
If I change the base class to NSObject and instead of initWithFrame override init (see bellow) then the leak will be detected....
so here is the code for leak that WILL be detected
@interface LeakTestView : NSObject
- (id) init;
@end
@implementation LeakTestView
- (id) init {
NSLog(@"init called");
self = [super init];
if (self) {
}
return self;
}
@end
If I create object now and leave it - the leak detection will trigger and the leak will be "seen" into the Instruments.
- (IBAction)leak:(id)sender {
LeakTestView* leak=[[LeakTestView alloc]init];
NSLog(@"class is %@", [leak class]);
}
Any ideas what is going on? Why the leak of the UIView subclass will not be detected but changing the base class to NSObject will "fix" the issue? Oh and yes the leaked object can be seen using the "Mark heap" - one mark before the leak and one mark after I click the button and create the leak - the class will be seen into the heap delta...
EDIT: one more "funny" situation... If I remove the "init" stuff (only alloc the object)
LeakTestView* leak=[LeakTestView alloc];
then the leak will be detected no matter what is the base class... What the hell is going on here?
EDIT2: one more "funny" thing. The Leak detection issue can be observed only in Simulator (iOS 5.0, 9A334 is mine) but the leak will be detected always if using the iPad device...
Any comments? If you dont have the issue or consider that I speek "lies" just tell me I am wrong and the above case is working "just fine" - leaks I describe are detected by your xCode instruments!