I actually think it may retain cached information when you close out the UIWebView. I've tried removing a UIWebView from my UIViewController, releasing it, then creating a new one. The new one remembered exactly where I was at when I went back to an address without having to reload everything (it remembered my previous UIWebView was logged in).

So a couple of suggestions:

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];

This would remove a cached response for a specific request. There is also a call that will remove all cached responses for all requests ran on the UIWebView:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

After that, you can try deleting any associated cookies with the UIWebView:

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

    if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}

Let me know where that gets you.

I had nearly the same problem. I wanted the webview cache to be cleared, because everytime i reload a local webpage in an UIWebView, the old one is shown. So I found a solution by simply setting thecachePolicy property of the request. Use a NSMutableURLRequest to set this property. With all that everything works fine with reloading the UIWebView.

NSURL *url = [NSURL fileURLWithPath:MyHTMLFilePath];
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
 [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
 [self.webView loadRequest:request];

Hope that helps!

Don't disable caching completely, it'll hurt your app performance and it's unnecessary. The important thing is to explicitly configure the cache at app startup and purge it when necessary.

So in application:DidFinishLaunchingWithOptions: configure the cache limits as follows:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    int cacheSizeMemory = 4*1024*1024; // 4MB
    int cacheSizeDisk = 32*1024*1024; // 32MB
    NSURLCache *sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
    [NSURLCache setSharedURLCache:sharedCache];     // ... other launching code
}

Once you have it properly configured, then when you need to purge the cache (for example inapplicationDidReceiveMemoryWarning or when you close a UIWebView) just do:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

and you'll see the memory is recovered. I blogged about this issue here:http://twobitlabs.com/2012/01/ios-ipad-iphone-nsurlcache-uiwebview-memory-utilization/

You can disable the caching by doing the following:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
 

iphone 如何清空UIWebView的缓存的更多相关文章

  1. iOS UIWebView清除缓存

    UIWebView清除Cookie: //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieSto ...

  2. uiwebview 清缓存。,mark

    //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCook ...

  3. UIWebView清除缓存和cookie[转]

    现在项目遇到一个问题,游戏底层用Cocos2d-x,公告UI实现是用的UIWebView, 然后第一次在有网络的环境下运行公告UI,会加载url链接,同时就会自动存入缓存,当下次手机没有网络的环境下, ...

  4. uiwebview 离线缓存 图片

    uiwebview 离线缓存图片

  5. 清除UIWebView的缓存

    //清除cookies NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCook ...

  6. shell脚本清空redis库缓存

    前提: 现在做的一个业务系统,用了redis做缓存. 系统做了缓存,通常在系统正常使用的过程中,可以节省很多系统资源,特别是数据库资源. 但是,在开发.测试或者系统遇到问题的时候,也有很麻烦的事情. ...

  7. web调试-禁止/清空chrome页面缓存

    Chrome会对页面缓存,web页面调试的时候,后端修改页面.js之后,刷新页面经常不生效,非常不方便. 有一些小技巧可以解决该问题. 技巧一: 开发者工具-setting/设置,可以关闭缓存. 开发 ...

  8. 清空chrome浏览器缓存

    缓存是一个很深奥的东西,虽然查了半天,还是没有搞清楚,希望以后可以遇到前端大神,可以给一个傻瓜化的通俗易懂的解释 已经上线的,后续有迭代的软件,迭代的版本不应该手动清除缓存了,因为太麻烦,对客户来说不 ...

  9. UIWebView的缓存策略,清除cookie

    缓存策略 NSURLRequestCachePolicy NSURLRequestUseProtocolCachePolicy缓存策略定义在 web 协议实现中,用于请求特定的URL.是默认的URL缓 ...

随机推荐

  1. CentOS7 安装 PostGIS方法(适合国内网络

    安装Postgresql 9.4 yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1. ...

  2. 在线最优化求解(Online Optimization)之四:RDA

    在线最优化求解(Online Optimization)之四:RDA 不论怎样,简单截断.TG.FOBOS都还是建立在SGD的基础之上的,属于梯度下降类型的方法,这类型方法的优点就是精度比较高,并且T ...

  3. Why am I able to change the contents of const char *ptr?

    http://stackoverflow.com/questions/3228664/why-am-i-able-to-change-the-contents-of-const-char-ptr I ...

  4. 检测php网站是否已经被攻破的方法

    0x01 查看访问日志 看是否有文件上传操作(POST方法), IPREMOVED - - [01/Mar/2013:06:16:48 -0600] "POST/uploads/monthl ...

  5. jQuery.validate errorPlacement

    在被验证的控件的后一个元素控制显示 errorPlacement: function(error, element) { element.next().css("color",&q ...

  6. 如何解决VS启动越来越慢

    VS2013 用久后,现在启动和打开项目变得很慢 解决方案: A.清理缓存 VS2010清理缓存:启用vs2010命令行工具:在vs2010命令提示符下,执行devenv.exe /resetuser ...

  7. 谁会是 Zabbix 和 Nagios 的继任者?

    [编者按]本文根据 Dataloop.IO 的创始人兼 CEO David Gildeh 对监控工具市场的现状分析以及对未来发展趋势的展望,展开拓展讨论. 为什么监控还是一塌糊涂? 为了调研市场,从而 ...

  8. node.js 安装、图文详解

    网上的教程很多,有些模糊不清,有些版本太旧,有些是.exe安装,本文讲述windows系统下简单nodejs .msi环境配置.最新版是Current version: v0.10.26.官网下载地址 ...

  9. struts2学习笔记(2)——简单的输入验证以及标签库的运用

    struts2自带了一些标签库,运用好这些标签库会减少开发周期. 1.struts2标签库是在哪定义的? struts2标签库定义在struts2-core-2.1.8.jar这个文件中,具体在这个j ...

  10. ubuntu 13.10 64bit装BeyondCompare

    1. Beyond Compare官网下载amd-64位的,安装失败,依赖于ia32-libs,但是这个文件已经不在源里了: 2. 官网下载tar.gz源码包,解压安装失败: 3. 直接装32位的,可 ...