user1351584
user1351584

Reputation: 21

Memory continues to increase when loading images to Webview + Safari

I load HTML file which loads images using Javascript files to WebView. Every time when I load html file to Web view it shows me some memory increased in Activity Monitor. Even, when I release Webview then also it does not release the memory.

I am not caching the resources in Webview. But, when I used instruments to analyse the memory , it shows me images resources are cached in memory which does not get released.

I tried to load same HTML files in Safari browser, I found the same behavior.

Can anyone please guide me where I am missing? How can I optimize the memory loading to WebView?

Upvotes: 2

Views: 681

Answers (2)

user1351584
user1351584

Reputation: 21

More inputs how I try to avoid caching in WebView.

I am using below piece of code to remove caching.

    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];


    WebPreferences *the_pPrefs = [m_pWebView preferences];
    [the_pPrefs setCacheModel:WebCacheModelDocumentViewer];
    [the_pPrefs setUsesPageCache:NO];
    [m_pWebView setResourceLoadDelegate:self];

Even I handle resource load request in below delegate method.

- (NSURLRequest *)webView:(WebView *)sender 
            resource:(id)identifier 
     willSendRequest:(NSURLRequest *)aRequest 
    redirectResponse:(NSURLResponse *)redirectResponse 
      fromDataSource:(WebDataSource *)dataSource
{
      NSURL * url = [aRequest URL];
      NSURLRequest * cachelessRequest = [NSURLRequest requestWithURL:url    cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:100];
      return cachelessRequest;
}

I hope I doing the right things to avoid caching. Please give your thoughts for the same.

Upvotes: 0

Rob Keniger
Rob Keniger

Reputation: 46020

Do not use Activity Monitor for profiling memory performance in your app.

Use the Instruments app and the various memory-related tools it provides, such as Allocations and Leaks. You will then be able to determine if your app is truly leaking.

Upvotes: 1

Related Questions