user1120133
user1120133

Reputation: 3234

object leaked:allocated object is not referenced later

When i am analyzing it getting these messages:

Method returns an Objective-C object with a +1 retain count for the below statement

self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

Object leaked alocated object is not refrenced later in this execution path and has a retain count of + 1

[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

Anyone knows how to fix these messages.

Thanks for help.

Upvotes: 0

Views: 1391

Answers (2)

zaph
zaph

Reputation: 112855

Assuming that viewis a property with a retain attribute self.view retains the view so the retain created by initWithFrame is the additional retain that needs to be released.

SImple autorelease:

UIView *newView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

Better yet, if possible use ARC. ARC is available for iOS 4.x and above and on a file-by-file basis for a mixed implementation. Then, there are no retain, release or autorelease calls in the app.

Upvotes: 2

picciano
picciano

Reputation: 22701

self.view is a @property that is retained when it is set. You will need to release it.

Try:

UIView *newView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.view = newView; 
[newView release];

or

self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

Upvotes: 1

Related Questions