在我的应用程序中,我有一个uiwebview,我曾用它来显示图像文件。现在的问题是,我在此视图中泄漏。我写了以下代码:
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];
在代码的第一行中,我在其中分配uiwebview,为什么即使我发布了它也会泄漏它?
如果m_pWebView
属性是retain
或copy
,则需要确保在该类的dealloc
方法中释放它。我怀疑您没有将其释放。
您还应该在将self.m_pWebView添加到self.view之后释放它
在ViewDidLoad中
[self performSelectorOnMainThread:@selector(abc) withObject:nil waitUntilDone:YES];
然后使函数名称为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;
}