Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17027] iOS: The webview reloads on being removed and re-add to a window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2014-06-06T17:26:36.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sn/a
ComponentsiOS
Labelsqe-3.3.0, regression
ReporterSatyam Sekhri
AssigneeVishal Duggal
Created2014-05-26T09:39:45.000+0000
Updated2017-03-22T23:04:18.000+0000

Description

The webview reloads when re-added to a window after being removed. This is a regression as the issue does not occur on 3.2.3. Also the issue does not occur on Android. Steps to Reproduce: 1. Run the application 2. Click on the "remove and add webview" button 3. Click on the "remove and release and add webview" button Actual Result: The webview gets loaded at all the three steps. The alert "The webview is loaded" is shown on all the three steps Expected Result: The load event of webview should not be called when it is simply removed and re-added.
var win=Ti.UI.createWindow({backgroundColor:'white'});
var webview = Ti.UI.createWebView({
			html : '<html><head></head><body><script>var now = Date.now(); document.body.innerHTML = now;</script></body></html>',
			top : 0,
			height : 200
		});

		webview.addEventListener('load', function() {
			alert('The webview is loaded!');
		});

		var b = Ti.UI.createButton({
			title : "remove and add webview",
			top : 210
		});
		b.addEventListener("click", function() {
			win.remove(webview);
			win.add(webview);
		});

		var b2 = Ti.UI.createButton({
			title : "remove and release and add webview",
			top : 280
		});
		b2.addEventListener("click", function() {
			win.remove(webview);
			webview.reload();
			win.add(webview);
		});
win.add(webview);
win.add(b);
win.add(b2);
win.open();

Comments

  1. Vishal Duggal 2014-06-06

    This is an expected change in behavior on the iOS platform. The old behavior was that when you removed a child from a parent we would mark the JS object ready for GC and the view would be destroyed when the proxy was collected. In 3.3.0 we became more aggressive with the memory cleanup. Essentially when you remove a child from a parent we not only mark the JS object ready for GC but also send the detach message to the proxy so the view is immediately collected. So when you remove and readd, the view object is recreated and hence the load function gets called again. Marking this as Won't Fix.
  2. Hasnar Haz 2014-08-06

    I understand the aggressive approach. However, if a view is added to a new parent (a currently opened but obscured window) and then removed from the current parent, it is not garbage and so should not be collected. I expected the view to still be available (ie. not reloaded) when the new parent becomes the top window. If this is the expected behaviour in 3.3.0, is there a workaround to get the old behavior?
  3. Lee Morris 2017-03-22

    Closing ticket as "Won't Fix".

JSON Source