Telerik-Verified-Plugins / WKWebView

DEPRECATED - this plugin served a purpose in the past, but there are better implementation now
832 stars 149 forks source link

Memory leaking problem: WKWebView doesn't free memory #192

Open wilk opened 9 years ago

wilk commented 9 years ago

Hi there,

first of all, thanks for this plugin! I'm using WKWebView 0.6.5 for an hybrid application built with Ionic 1.0.0 + AngularJS 1.4, PouchDB 5.1.0 and cordova-sqlite-storage plugin 0.7.11. The application is launched on iOS 9.1 with XCode and it's the only running app on the system. The starting memory snapshot is the following:

start start

At the beginning, the memory is about 400MB: keep watching "Other Processes" memory. The application starts to download a 90MB db with PouchDB from a CouchDB server. As you can see, the memory always increases:

3 mins later -> 480MB 3mis

7 mins later -> 700MB 7mins

11 mins later -> 800MB 11mins

The app memory is fixed (from 10 to 30 MB) while the rest of the memory is increased from 400MB to 800+MB (as I said, is the only running app on the system).

To workaround it, I tried to reload the page with location.reload() and only 30MB of memory has been freed. The only way is to restart manually the entire app (so the WKWebView) but that's not a good solution.

Is there a way to free the memory? Why WKWebView is not freeing the memory?

EddyVerbruggen commented 9 years ago

How does your app behave with UIWebView, memory-wise?

wilk commented 9 years ago

@EddyVerbruggen it crashes (and sometimes happens with WKWebView too). The mainly difference is on the app memory and the "Other Processes" memory: with WKWebView the first one remains fixed and the second one increases while with UIWebView is exactly the opposite.

EddyVerbruggen commented 9 years ago

I'm guessing WKWebView's memory is represented in 'Other Processes' as well. Are you constantly adding data in your app?

wilk commented 9 years ago

Yep, that's right for both! Basically there's a login page: when the user performs the login, the app starts to sync its db (PouchDB replicate) and data is constantly added for 10 minutes more or less. Then, the application stands by for user interactions but the memory is not freed anyway. Now, I don't know if the problem regards the Javascript garbage collector or the WKWebView but I know that is not freed in both cases.

salamalejkum commented 9 years ago

It seems as if the memory is freed only when receiving memory warning or going to background mode. After such events everything seems to go back to normal.

klyonrad commented 8 years ago

For anyone wondering: This issue appears is also present with the official WKWebview plugin

For iPhone 6S the barrier for the webview crash seems to be around the 1,75GB memory mark.

It seems as if the memory is freed only when receiving memory warning or going to background mode. After such events everything seems to go back to normal.

What exactly do you mean with background mode?

hilkeheremans commented 8 years ago

It's possible there is also a link to Microsoft/cordova-plugin-code-push#158 -- even though in that case, we're talking the official WKWebview plugin.

rahulecomp commented 6 years ago

Is this something restricted to IOS9 or lower or does it occur even for IOS 10 and above ?

manishkumar0282 commented 6 years ago

I am facing this issue even on iPhoneX, iOS11.4.1 with the WKWebView.

rahulecomp commented 6 years ago

@manish0282 I eventually got rid of the WKWebView and used the native IOS webview. Although the crashes do occur it is slower in comparision to WKWebView. You would have to do appropriate garbage collection to address the issues you face in your application.

rafaelfl commented 6 years ago

It is happening to me too. After making some Firebase calls, the webview, in some devices, eventually crashes. I have returned my app to the UIWebView, even with several problems faced with it... Somone has discovered a solution?