Why UIWebView Eating so many Memory? - iphone

I'm using a UIWebView to load a pure Text HTML page for my iPad app. The size of the HTMP page is only 40KB. But when I use the instrument to monitor the memory use for loading the UIWebView, I found down it consumes like 20MB memory, if I scroll the web view, the memory is even getting higher. Finally I get a level 1 memory warning.
Could anyone help me with this? How could I reduce the memory for this? (I need to use the HTML to show the text here).
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html" inDirectory:#"SPC"];
NSURL *url = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];

htmlPath
url
request
release all of them after this line
[webView loadRequest:request];
then release webview in dealloc and use webview as ivar

Related

UIWebView back button not getting enabled

In my application I have a UIWebView in which I need to add browser like functionality(user can goBack,Forward or reload the page). To achieve this I have used the code for this tutorial.
In my code I have only one change in viewDidLoad:
I am loading data from a local html file like this:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:#"File name" ofType:#"html" inDirectory:NO];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[self.webView loadData:htmlData MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:[NSURL URLWithString:#""]];
instead of:
NSURL* url = [NSURL URLWithString:#"http://iosdeveloperzone.com"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
After loading initial html file if I am making any click on that page than the back button should get enabled, instead of its getting enabled after second url click and so that I am not able to go back to the original home page.
Please help me with this.
Thanks.
I got an answer. It's because you load data into the webView without loadRequest. If you load data into webView as a string, then it won't have any url to go back or load the old page. So it won't store the data you given to the webView. For that, you need to provide the url as like this.
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"File name" ofType:#"html"] isDirectory:NO]]];

How to load large size PDF scroll view in iOS?

I have pdf of size 53MB when i try to load only one page of PDF in scrollview i got memory warning and then application crash.
Display the PDF in a UIWebView:
NSString *PDFPath = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"pdf"];
NSURL *URL = [NSURL fileURLWithPath:PDFPath];
NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URL];
[webView loadRequest:URLRequest];
The WebView will load pages into memory as they appear on screen rather than all at once.
This is a duplicate of What is the best way to view large PDFs on iOS?
The accepted answer is to use a UIWebView as indicated above.
You should take a look at the vfr/Reader, which is a PDF Reader Core for iOS.
UIWebView is not very good in handling big files out of the box.

how to show rss feed url in UIWebView in iphone sdk?

I am trying to display url in UIWebView but I can not display, webview just call the fail with error method. My url is this "http://www.tekniknoktamarket.com/index.php?route=feed/google_base",
So please help me how to display this url in UIWebView *?*
In order to have a UIWebView download and display the content from a URL, you need to go through a couple of layers of abstraction, the first being an instance of NSURL, which contains your URL string. Then, you hand the NSURL to an instance of NSURLRequest. Finally, you hand the NSURLRequest to the webView. It all looks something like this:
NSURL *url = [NSURL URLWithString:#"www.your-url.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[yourWebView loadRequest:request];
That should do it.
This is the code loading a URL into a webview:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.theurl.com"]]];
If you're using this code and are encountering any problems, please provide the code you were using and the exact error

how to pass value through NSURL

i was trying to pass value to a native html page from my web view application
I try
url=[NSString stringWithFormat:#"%#?bob=123&frank=321&tom=213",url];
but when i build and debugging program, application crashes showing “EXC_BAD_ACCESS”
Please help me if anyone knows how to do this.
The UIWebView class only supports loading of URLs using the NSURLRequest class. To do what you want to do, you'll need this:
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:#"%#?bob=123&frank=321&tom=213", base]];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];

caching the webcontent ( images ) on the iPhone

I have a question concerning the caching of webcontent.
I've created a UIWebview component
Code:
NSString *urlAddress = #"http://192.168.55.101/~test/mobile/iphone/ads/v0.1/";
//URL OBJECT footer
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320 , 100)];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
This shows a picture in my iPhone.
I've tried looking into cache attributes and functions (for instance NSURLRequestReturnCacheDataElseLoad ) to see which options I have , but what's the best way to cache the image appearing in this screen.
Or how do I use NSURLRequestReturnCacheDataElseLoad?
There is a good sample code:
Apple sample code
Description:
CacheInfo allows you to choose a URL, create a connection, load the resource asynchronously, and observe results such as the data size, load time, and cache usage. You can adjust the sizes of the shared memory and disk caches and observe how caching is affected during the load.