Post not yet marked as solved
I just tried latest Xcode 15.4 RC with a new 17.5 Beta release and the problem is resolved :-)
So I assume the final release will also be OK.
Panic over :-)
Post not yet marked as solved
For completeness, I created the simplest app possible that illustrates this:
//
// ContentView.swift
// TestWKWebView
//
//
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
SVGWebView()
}
}
struct SVGWebView: UIViewRepresentable {
let svg: String = "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><title>Hello ...</title></head><body><p>Greetings ...</p></body></html>"
func makeUIView(context: Context) -> WKWebView {
return WKWebView(frame: CGRect.zero)
}
func updateUIView(_ webView: WKWebView, context: Context) {
webView.loadHTMLString(svg, baseURL: nil)
}
}
#Preview {
ContentView()
}
This fails too, as I suspected, but worth doing anyway. It works fine on ios 17.5 or earlier.
Post not yet marked as solved
I also tried on VisionOS 1.2 (beta) and this works fine. For completeness I also tried iPad (17.5 beta) but that has the same issue iPhone 17.5 has. So it seems a generic issue with ios on iphone and ipad, but it is not an issue with the latest visionOS release.
Post not yet marked as solved
For me this seems limited to the iOS version - and for now just on a simulator (not been able to try on a real device yet... until 17.5 is released officially). I am using Xcode 15.4 Beta to build the App, but it works just fine in ios 17.4 or earlier.
Post not yet marked as solved
Hi - this was super helpful. Sorry I took so long to get back on this but your suggestions help me identify the retain cycle that prevented the JS Core from being cleaned up properly. I had a thread I was running (handling timers initiated in the JS layer) but when the thread was shut down I did not do it cleanly (I just blindly called Thread.exit()) but I needed to shut the thread properly and let it deallocate any retained references. Once I did that i suddenly saw the retain cycles disappear.
Post not yet marked as solved
hi - thanks for the very fast response :-)
My set up pushes a large JS file into the core, does some work, and then recycles (by just nullifying the JSContext object, as you do). If I look at memory consumption, it goes up when I insert the javascript into the core and execute JavaScript functions (in my case it jumps by about 100MB as I have a lot of JavaScript code ...) On dereferencing the JSContext and looping round, no discernible drop in memory happens. If I then loop back I end up increasing memory by approx 100MB each time ... so the memory consumption grows a lot :-)
I'll see if I can create a more simple setup and share it. My current app is not really something that is easy to work with :-)
chris