uiwebview分配上的内存泄漏

问题描述 投票:0回答:3

在我的应用程序中,我有一个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,为什么即使我发布了它也会泄漏它?

iphone memory-leaks uiview uiwebview
3个回答
2
投票

如果m_pWebView属性是retaincopy,则需要确保在该类的dealloc方法中释放它。我怀疑您没有将其释放。


0
投票

您还应该在将self.m_pWebView添加到self.view之后释放它


0
投票

在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;

 }
© www.soinside.com 2019 - 2024. All rights reserved.