views:

59

answers:

2

hi everyone. in my app i have a uiwebview which i used to display image file. now the problem is i am getting a leak in this view. here i have written the following code.

UIWebView *the_pWebView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; // the leak is on this line. 
the_pWebView.backgroundColor = [UIColor whiteColor];
the_pWebView.scalesPageToFit = YES;
the_pWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
the_pWebView.delegate = self;

self.m_pWebView = the_pWebView;
[self.view addSubview: self.m_pWebView];
[the_pWebView release];

can somebody plz tell why the frist line of the code, where i am allocing the uiwebview would be leaking. even if i have released it?

+2  A: 

If the m_pWebView property is retain or copy then you need to make sure you release it in your dealloc method on that class. I suspect you're not releasing it there.

jer
for m_pWebView, i have defined property(nonatomic, retain) and have also released it in the dealloc method. even then this leak is being shown.
Jayshree
A: 

You should also release self.m_pWebView after adding it to self.view

Meir Assayag
i have released it in the dealloc method. i cannot release it as soon as i add it to self.view. i use it other places too.
Jayshree
The retain count after adding it to self.view is 2, you should then release it so as the dealloc function can destroy it completely!
Meir Assayag
Update: if you add the self.m_pWebView to self.view, you are not responsible anymore of its deallocation(if you release it after the adding operation). self.view will destroy its subviews on dealloc.
Meir Assayag