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. 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];
In the first line of the code, where I am allocing the uiwebview, why would this be leaking even if I have released it?
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.
您还应该在将 self.m_pWebView 添加到 self.view 后释放它
in ViewDidLoad
[self performSelectorOnMainThread:@selector(abc) withObject:nil waitUntilDone:YES];
then make a function name is abc
-(void) abc
{
UIWebView *the_pWebView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
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];
iWebView=nil;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.