简体   繁体   中英

UIWebView leaking memory when loading .RTF files?

Trying to load a .rtf file (2.4 MB) via webView like this:

 NSURL *docURL = [NSURL fileURLWithPath:docPath];
NSData *data = [NSData dataWithContentsOfURL:docURL];
NSString *mimeType = //receiving proper mime type here
[webView loadData:data MIMEType:mimeType textEncodingName:@"utf-8" baseURL:docURL];

Loading such files leads to memory growth until app crashes. According to the Instruments memory growth continues even after complete deallocation of webView containing controller and webView itself. Being in other place of the application, using other app features, memory grows as if I'm still continuing browsing that .RTF file.

When closing/dismissing the controller I also do all things to deallocate WebView. That is: mainWebview.delegate = nil; [mainWebview stopLoading]; , [mainWebview removeFromSuperview]; , [mainWebview release]; . (Even tried to do the following: [mainWebview loadHTMLString:@"" baseURL:nil]; )

What I see in instruments: 在此处输入图片说明

Does anybody have any ideas? Thanks.

EDIT: I tested some large .RTF files (700 Kb - 2.4 Mb) on Safari, Chrome, Mercury browsers. Same thing happens everywhere, both simulator and device. I guess it's some bug in WebKit.

General situation: browsers use too much memory to process this kind of files. In 90% of cases just abnormally exit with "Crash" or "Low Memory" signal. If device handles peak memory usage when loading the file then memory drains back to normal, if not - it crashes.

I have also had several issues related to memory management when using UIWebView . In my case , I saw that behavior changed a lot depending on the way I loaded data into the web view. In your case, I have no solution, but based on my experience, maybe using:

NSURLRequest *req = [NSURLRequest requestWithURL:urlToYourRTFFile];
[webView loadRequest:req];

could make a difference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM