Zhen
Zhen

Reputation: 12431

Object leaked: Object allocated and stored is not referenced later in this execution

After using the analyze tool, I am getting the following warning "Object leaked: Object allocated and stored is not referenced later in this execution"

enter image description here

How can I remove this warning?

Upvotes: 0

Views: 2024

Answers (3)

X Slash
X Slash

Reputation: 4131

It's because you allocate your

UIWebView* videoView = [UIWebview alloc] initWithFrame:CGRectMake(0, 0, 104, 104)];

but then in your if statement, you assign this videoView with something else, hence you're losing pointer to the initial allocated object.

Change your declaration to

UIWebView* videoView = nil;

then in your else

videoView = [UIWebview alloc] initWithFrame:CGRectMake(0, 0, 104, 104)];

Upvotes: 2

zrslv
zrslv

Reputation: 1846

You have to release previous object referenced by videoView, before assigning a new value.

Upvotes: 0

Simon Lee
Simon Lee

Reputation: 22334

Inside the IF block you reassign your UIWebView without EVER having used the initial assignment. Instead have something like this...

UIWebView *videoView = nil;

if([self.webViewCache objectForKey:cellId]) {
    videoView = .....normal code here
} else {
    videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 104, 104)];
    .... normal code here
}

Upvotes: 10

Related Questions