IOS leak detection issue with xCode 4.3

I have a very strange problem with xCode 4.3 memory leak tools ... Basically this does not work in the following case ...

  • The project is created without the support of ARC.
  • Create a simple class that inherits from UIView
  • use "button" to instantiate this class and "leak" it ... the leak will not be caught using Leak Instruments

so here is the code for 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'm creating a 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 changed the base class to NSObject and instead of initWithFrame will override init (see below), then the leak will be detected ....

so here is the leak code 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 an object now and leave it, a leak detection will cause and the leak will be “visible” in the Tools.

 - (IBAction)leak:(id)sender { LeakTestView* leak=[[LeakTestView alloc]init]; NSLog(@"class is %@", [leak class]); } 

Any ideas what is going on? Why won't a leak of the UIView subclass be detected, but changing the base class to NSObject will “fix” the problem? Oh, and yes, the leaked object can be seen using the "Heap Mark" - one label before the leak and one label after I press the button and create the leak - the class will be visible in the delta heap ...

EDIT: Another “funny” situation ... If I delete the “init” stuff (just select the object)

 LeakTestView* leak=[LeakTestView alloc]; 

then the leak will be detected no matter what the base class is ... What the hell is going on here?

EDIT2: Another “fun” thing. A leak detection problem can only be observed in Simulator (iOS 5.0, 9A334 is mine), but a leak will always be detected if you use an iPad device ...

Any comments? If you don’t have a problem or think that I’m spying a “lie”, just tell me that I’m wrong, and the above case works “perfectly” - the leaks that I describe are detected by your xCode tools!

+6
source share
1 answer

Perhaps this is not a leak?

You call a method that is a black box. Implementing a UIView initWithFrame is nothing from your business. This one has a contract at its discretion, but you do not have the right to demand more leakage from it than you can assume that the number of deductions is 1.

Leaks are a useful tool, but they don’t do what you think. This does not tell you when you messed up. He informs you when you have unreachable distributions. This is not the same thing.

Or it could be a mistake.

0
source

Source: https://habr.com/ru/post/909484/


All Articles