I have a web app that loads images from a zip file, and displays them successively.
The zip file can store many images.
To prevent from running out of memory, the memory is managed, by cleaning the memory from previous images before showing the next image.
This is done by:
setting the buffer to null.
revoking the object url and setting the url to null.
This approach works well on various OSs such as Windows, Linux, and MacOS.
But on iOS it fails.
In the example, a set of images from a zip file is displayed in a loop, to mimic a zip file with many images.
Setting the variable doDebugMemoryLeakOn_iOS_withRevoke to true, activates the code
URL.revokeObjectURL(fileInfo.url);
which causes the problem, after some time (after ~1100 images on my iPad Pro).
The problem can be seen by running the program and selecting the zip file:
https://cdn.jsdelivr.net/gh/avnermosh/example8_memoryLeakOn_iOS/example8_take2_3images.zip
(or any other zip file with several jpeg images - the linked zip file simply contains 3 images in size of 4032x3024)
At some point, the program fails with an error message: "The I/O read operation failed"
This happens on various iOS devices (e.g. iPad, iPhone8) with various iOS versions (iOS 15.2, iOS 14.8.1) when played in various browsers (e.g. Safari, Chrome, Firefox) after about 1000 images.
It also happens in a native iOS app that uses WKWebView.
I suspect that there may be a problem with the WKWebView browser engine, which is common to all these browsers.
Note: several places commented on adjusting the Safari settings e.g. GPU Process: Canvas Rendering
This somewhat deferred the problem but at some point the error still occurs.
After the problem occurs, there is no way to recover programatically, e.g. by retrying to read the zip file entry or skipping to the next zip entry.
The only solution is to select the file again.
Could this indicate a bug in WKWebView?
How can this be fixed, or worked around?
Thanks
p.s. I also placed the question on stackoverflow that describes the problem in details and shows a link to the online example that demonstrates the problem.
Post
Replies
Boosts
Views
Activity
I have a Hybrid webapp that runs on iOS and uses wkwebview.
The user click on a button, selects a local file, and receives a variable with File API structure, which includes the filename (file1.zip).
A call is triggered from the javascript side to the iOS (objective-c) with the name of the file.
I want to open the file on iOS side using objective-c. But for that I need to know the path of the file.
Incidently, I do see a print-out in iOS when selecting the file:
file:///private/var/mobile/Containers/Data/Application/9CCE059F-2B96-46DD-9528-18B806CEC5E6/Documents/file1.jpg
So I assume that the path of the file is:
/private/var/mobile/Containers/Data/Application/9CCE059F-2B96-46DD-9528-18B806CEC5E6/Documents
But, is there a proper / methodical way to get the file path similar to the filename?
Thanks