We as a team of engineers work on an app intended to visualize medical images. The type of situations where the app is used involves time critical decision making for acute clinical conditions. Stability of the app and performance are of almost importance and can directly help timely treatment action. The app we are developing uses Javascript. It has been observed the footprint of the app is lagging by 2 to 3 seconds in releasing memory while javascript is expecting the memory to be cleared. This is affecting the stability of our application and preventing us in delivering the right quality of application.
The problem specifically can be described as follows, using javascript create an array and then remove it and after removal of the array, create a new array of the same size immediately and again remove it. Because the memory is not released in time, if you repeat these steps a few times the app memory footprint will increase and that crashes the app.
To reproduce this scenario, we have created a simple app which creates an array with size of 100MB and checks the memory footprint using the Xcode instrument tool. When we create an array of 100MB size, sometimes it shows the memory footprint peak of around 700MB-800MB and when we clear the array by assigning it with an empty array it releases the memory after 2-3 seconds.
Considering the critical nature of the app, I urge you to look into this and provide necessary support and resolution.
Please refer below sample code that will help to reproduce the mentioned scenario.
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
@IBOutlet var webView: WKWebView!
let myHTML = """
<!DOCTYPE html>
<html>
<head>
<style>
.button-style {
width: 400px;
height: 200px;
margin: 15px;
font-size: 50px;
}
</style>
</head>
<body>
<button type="button" class="button-style" onclick="loadDataInCache()">Load Data In Cache</button>
<button type="button" class="button-style" onclick="removeDataFromCache()">Clear Cache</button>
<script>
const size = 1024 * 1024 * 100;
let numberArray = [];
function loadDataInCache() {
numberArray = Array(size).fill(0);
}
function removeDataFromCache() {
numberArray = [];
}
</script>
</body>
</html>
"""
override func viewDidLoad() {
super.viewDidLoad()
// self.view.addSubview(webView)
webView.loadHTMLString(myHTML, baseURL: nil)
}
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
}