iPhone - 内存泄漏 - NSData dataWithContentsOfUrl& UIWebView的 [英] iPhone - Memory Leak - NSData dataWithContentsOfUrl & UIWebView

查看:671
本文介绍了iPhone - 内存泄漏 - NSData dataWithContentsOfUrl& UIWebView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙!一直盯着这个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)

alt text http://img.skitch.com/20081110- j5tn5n7ixph95ys4rpchibaw5p.preview.jpg

查看图片

2 - 运行它以确认没有泄漏(如预期的那样)

2 - Run it to verify no leaks (as expected)

替代文字http://img.skitch.com/20081110-fy2qrkgy47hm4fe2f1aakd4muw.preview.jpg

查看图片

3 - 打开ViewController.xib,只需从库中添加一个UIWebView(无需连线)

3 - Open the ViewController.xib and simply add a UIWebView from the library (no need to wire it up)

alt text http://img.skitch.com/20081110-d63c3yh1a1kqiciy73q8uyd68j.preview.jpg

查看图片

4 - 运行它以验证是否有泄漏! (为什么???)

4 - Run it to verify there are leaks! (why???)

替代文字http://img.skitch.com/20081110-qtxcfwntbcc3csabda3r6nfjg6.preview.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.

推荐答案

我也遇到了来自NSData的 dataWithContentsOfURL:的泄漏问题iPhone模拟器。我发现当我使用其他方便方法( 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& UIWebView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆