在uiwebview分配内存泄漏
问题描述:
在我的应用程序我有一个uiwebview我用来显示图像文件。现在的问题是我在这个视图中泄漏了。这里我写了下面的代码。在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.view
答
在viewDidLoad中
[self performSelectorOnMainThread:@selector(abc) withObject:nil waitUntilDone:YES];
然后做一个函数名后释放self.m_pWebView是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;
}
为m_pWebView,我已经定义属性(非原子的,保留),并且已经在dealloc方法中发布了它。即使这个泄漏正在显示。 – Jayshree 2010-09-06 09:32:19