UIWebView快速滚动显示大图导致内存警告崩溃
UIWebView fast scrolling to show large image lead to memory warning crash
当我在 iPhone6 Plus (iOS 8.4.1,Xcode 7.2.1)
上测试我的应用程序时,我发现当我滚动 webView FAST(缓慢滚动没有错)时显示两个大图片,我收到内存警告并崩溃。(该页面还充满了大量其他小图片)
但是在iPhone4s(iOS 7.1)
和iPhone5s(iOS 9.2.1)
上做同样的操作没有问题
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[_webView loadRequest:request];
我试过这个来修复内存警告,但还是不行
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[self fixMemoryWarningCrashMethod];
}
- (void)fixMemoryWarningCrashMethod
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
经过我不遗余力的解决,包括清理内存和磁盘缓存,UIWebView内存占用高是事实 - problem.So留给html开发者解决页面适合大屏幕 iPhone
当我在 iPhone6 Plus (iOS 8.4.1,Xcode 7.2.1)
上测试我的应用程序时,我发现当我滚动 webView FAST(缓慢滚动没有错)时显示两个大图片,我收到内存警告并崩溃。(该页面还充满了大量其他小图片)
但是在iPhone4s(iOS 7.1)
和iPhone5s(iOS 9.2.1)
上做同样的操作没有问题
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[_webView loadRequest:request];
我试过这个来修复内存警告,但还是不行
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[self fixMemoryWarningCrashMethod];
}
- (void)fixMemoryWarningCrashMethod
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitDiskImageCacheEnabled"];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitOfflineWebApplicationCacheEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
经过我不遗余力的解决,包括清理内存和磁盘缓存,UIWebView内存占用高是事实 - problem.So留给html开发者解决页面适合大屏幕 iPhone