问题描述
请帮忙!已经盯着这个看了 12 个小时;并在网上查找并找不到解决方案.
Please help! Have been staring at this for 12 hours; and have looked online and can't find solution.
在我的应用程序中,我在单独的页面/控制器中使用了 2 个 UIView 控件:
In my application, I use 2 UIView controls in separate pages/controllers:
- UIImageView(通过NSData dataWithContentsOfUrl)
- UIWebView
为了隔离我的代码并使其更易于解释,我创建了一个名为MyTestApplication"的基于视图的新项目
Just to isolate my code, and make it easier to explain, I created a new view based project called "MyTestApplication"
1 - 我在委托函数中添加了一个简单的 NSData dataWithContentsOfUrl.
1 - I added a simple NSData dataWithContentsOfUrl in the delegate function.
NSData *imageData = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://www.google.com/intl/en_ALL/images/logo.gif"]];
(这里没有发布,因为都是使用便利功能)
(Nothing to release here since it's all using convenience functions)
替代文本 http://img.skitch.com/20081110-j5tn5n7ixph95wppre.jpg
2 - 运行它以验证没有泄漏(如预期)
2 - Run it to verify no leaks (as expected)
替代文字 http://img.skitch.com/20081110-fy2qrkgy41hm4viewf.jpg
3 - 打开 ViewController.xib 并简单地从库中添加一个 UIWebView(无需连接)
3 - Open the ViewController.xib and simply add a UIWebView from the library (no need to wire it up)
替代文字 http://img.skitch.com/20081110-d63c3qicyh161kqiciy73q8uyd68j.preview.jpg.jpg
4 - 运行它以验证是否存在泄漏!(为什么???)
4 - Run it to verify there are leaks! (why???)
替代文字 http://img.skitch.com/20081110-qtxcfwntbj6rnf.jpg
我做错了什么?请帮忙!
What am I doing wrong? Please help!
如果我使用 UIWebView,为什么 NSData 会导致内存泄漏?我只是不明白.谢谢.
Why would NSData cause memory leak if I'm using UIWebView? I just don't get it.Thanks.
推荐答案
我也遇到了 iPhone 模拟器中 NSData 的 dataWithContentsOfURL:
泄漏问题.我发现当我使用其他方便的方法 (dataWithContentsOfURL:options:error:
) 时,我不会出现内存泄漏.
I was also having trouble with leaks from NSData's dataWithContentsOfURL:
in the iPhone simulator. I found that when I used the other convenience method (dataWithContentsOfURL:options:error:
) I would not get the memory leak.
我的代码看起来像这样:
My code looked something like this:
NSURL *url = [NSURL URLWithString:urlString];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:url
options:0
error:&error];
这篇关于iPhone - 内存泄漏 - NSData dataWithContentsOfUrl &网页视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!