美文网首页
UIWebView内存泄露解决方案

UIWebView内存泄露解决方案

作者: 小杰杰杰 | 来源:发表于2016-11-14 12:24 被阅读59次

原文链接UIWebView Secrets - Part1 - Memory Leaks on Xmlhttprequest

如果你懒得看,直接看这里:
文章中主要说的是html中的js代码发起Xmlhttprequest请求时会引起内存泄露。

var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      // Do whatever you want with the result
      
    }
  };
  xmlhttp.open("GET", "http://your.domain/your.request/...", true);
  xmlhttp.send();

解决这个问题的方法是在webViewDidFinishLoad方法中设置如下:

  [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];

相关文章

网友评论

      本文标题:UIWebView内存泄露解决方案

      本文链接:https://www.haomeiwen.com/subject/isshpttx.html