3

I am creating a very simple app in android. This app has 1 WebView. and on index.html file.

What I want to do is, I want to run index.html in WebView(Successful)

What index.html is doing is, It takes 3 videos from the same folder and run that videos one by one in the infinite loop. Everything works smooth, however, the biggest issue I can see is in memory profiler.

after testing application for the long run, I have found that Native memory keeps rising and not going down. this is really strange.

What I have done till so far,

1) Testing the app in different WebView versions,

2) Testing the same issue with creating project in Cordova,

3) Developing the same thing in ionic,

4) Calling System.gc() every after an hour,

5) removing all possible code from HTML and javascript

6) Creating native project loading webview and showing index.html in that

Please check code index.htm code below.

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial;
  font-size: 17px;
}

#myVideo {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width: 100%; 
  min-height: 100%;
}

.content {
  position: fixed;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  color: #f1f1f1;
  width: 100%;
  padding: 20px;
}

#myBtn {
  width: 200px;
  font-size: 18px;
  padding: 10px;
  border: none;
  background: #000;
  color: #fff;
  cursor: pointer;
}

#myBtn:hover {
  background: #ddd;
  color: black;
}
</style>
</head>
<body>

<video id="homevideo" width="100%" autoplay onended="run()" muted>
    <source src="video1.webm" type="video/webm">
Your browser does not support HTML5 video.
</video>

<script>

video_count =1;
videoPlayer = document.getElementById("homevideo");

function run(){
        video_count++;
        if (video_count == 4) video_count = 1;
        var nextVideo = "video"+video_count+".webm";
        videoPlayer.src = nextVideo;
        videoPlayer.play();
   };

</script>

</body>
</html>

Let me know if anything further information is required.

.enter image description here

Also check profiler report.

Thanks in advance.

======================= Further analysis ===================

After spending a whole day and running index.html in android native browser app "com.android.browser". It gives almost same result. Chart continue to rise. Please check the graph attched enter image description here

Pulah Nandha
  • 774
  • 4
  • 23
  • I can't give the problem exactly, but never put anything in index.html other than main things (links of maps...) . Index.html is the main loading part of the app, and its a redirecting point, so put your files in a normal ionic page and then without putting the js loop, just put the videos inside the page.html and leave the ts file empty and run your app and see if overheats again, if it didn't then the overheat is from the loop you created else recomment here and i'll see more about.. – Mostafa Harb Apr 07 '20 at 07:01
  • @MostafaHarb : Problem is when I run index.html, over a period of time, native memory(in blue colour) keeps increasing. which eventually lead to app crash. Furthermore, this index.html is a for the core understanding of the issue. otherwise, I have followed the guidelines which you have suggested. – Pulah Nandha Apr 07 '20 at 07:13
  • And is the memory still rising? – Mostafa Harb Apr 07 '20 at 07:19
  • @MostafaHarb Yes – Pulah Nandha Apr 07 '20 at 07:24
  • What is the devi e you are using? – Mostafa Harb Apr 07 '20 at 07:31
  • Its an emulator provided by android studio. even in real device shows the same issue. – Pulah Nandha Apr 07 '20 at 08:09
  • If you create a new project, without adding anything in it, and build it, will it also give memory rise also? – Mostafa Harb Apr 07 '20 at 08:14
  • @MostafaHarb Yes, Infact this is also a new project, and also I have created the new one and tried too – Pulah Nandha Apr 07 '20 at 09:22
  • In fact this is not a cordova or ionic bug, its something else coups be related to things other than the framework itself. – Mostafa Harb Apr 07 '20 at 09:27
  • I have tried with native webview as well with Android native project. by loading index.html keeping it in asset folder – Pulah Nandha Apr 07 '20 at 09:29
  • That whats i'm saying, maybe the webview itself my have the bug , maybe the gradle when building the apk have a bug which is causing app to overwork... there could be many problems which i couldn't know without testing... so for now try to upgrade android studio and its plugins, update emulator maybe, download latest gradle from gradle.org , since your problem as i said is not from framework or code , the problem is related to other unknown things. – Mostafa Harb Apr 07 '20 at 09:34
  • I have checked for android studio, Android SDK, and gradle. All are up to date. – Pulah Nandha Apr 07 '20 at 09:53
  • Is there something to update for webview? Search about it. I can't know where is the problem it didn't happen to me before such a bug. – Mostafa Harb Apr 07 '20 at 09:55
  • My current version of webview in the emulator is 74.0.3729.185. I have tried to upgrade it. But No further update allowed. – Pulah Nandha Apr 07 '20 at 10:12
  • https://github.com/facebook/react-native/issues/13413 https://medium.com/@AnilSisodiya/android-app-memory-leak-identification-and-fixing-440b589cd25e https://developer.android.com/guide/webapps/managing-webview https://stackoverflow.com/questions/17741297/webview-eating-up-too-much-memory – Mostafa Harb Apr 07 '20 at 10:23
  • Check these 4 sites that discus the same problem on different platform and try if it solves the problem. – Mostafa Harb Apr 07 '20 at 10:24
  • @MostafaHarb Thank you for the links. I have gone through all of them. This wont be the case in my app. Since I have just one activity containing webview. So I am not switching the activity. Its just loading a webview. loading index.html in webview and keeping that on for a very long time. – Pulah Nandha Apr 07 '20 at 10:46
  • I am talking about some work around maybe you could find in them since as you can see its not a bug known much, i have an s3 for testing and other new devices and i work mostly with hybird apps which are webviews and even on s3 there is no much memory taken or performance leak, your problem is weird and till now i can't know why this peoblem could be happening with you... – Mostafa Harb Apr 07 '20 at 10:51
  • @MostafaHarb I tried running my index.html in android native browser. surprisingly, It also shows memory leak. Please check updated question and screenshots attached. – Pulah Nandha Apr 09 '20 at 07:26
  • What is tour device version and what is emulator device version? – Mostafa Harb Apr 09 '20 at 19:33
  • @MostafaHarb you mean webview version? – Pulah Nandha Apr 10 '20 at 06:01
  • Mobile version itself, what is the device name? – Mostafa Harb Apr 10 '20 at 06:05
  • Actually the real device I am testing on is the customised device so dont have much information about it and the emulator that I am testing on is 10.1 WXGA (Tablet) API 29 1 GB ram and 80MB VM heap. – Pulah Nandha Apr 10 '20 at 06:09
  • Ok, on emulator it normally have much memory than normal device and to be sure from that , open any thing in device like gallery or gmail app or playstore and see if memory also increase... – Mostafa Harb Apr 10 '20 at 06:19
  • Ok... Let me try that. – Pulah Nandha Apr 10 '20 at 07:22
  • @MostafaHarb I tried multiple other apps. but in none of the other app, such memory rise is been observed. – Pulah Nandha Apr 13 '20 at 05:07
  • Did you find a solution? I think i have the same problem with capacitor – RacoonOnMoon Sep 22 '20 at 10:09
  • @RacoonOnMoon I couldnt find proper solution. So I made a patch, Simply restart an activity every after some time interval. – Pulah Nandha Sep 23 '20 at 04:57
  • @PulahNandha thanks alot for your hint. I am restarting my app every 6 hours by calling document.location.href = "index.html". Still it leaks. Could you explain what exectly you mean by restarting/patching the activity. – RacoonOnMoon Sep 23 '20 at 08:03
  • @RacoonOnMoon I was developing app in native android. and was using web view. and the container of a webview has tobe restarted. which I did. In your case may be restarting the whole application or Restarting the ionic instance may help. (Not sure though.) – Pulah Nandha Sep 23 '20 at 08:22
  • Thanks alot, i will try it :) – RacoonOnMoon Sep 23 '20 at 09:09
  • @PulahNandha i restarted the whole app with. ProcessPhoenix.triggerRebirth(context); Still it seems to leak. DO you have any other idea – RacoonOnMoon Oct 22 '20 at 05:17

0 Answers0