Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6463] iOS:JavaScript Object is incorrectly garbage collected.

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-02-27T20:07:45.000+0000
Affected Version/sRelease 1.8.0, Release 1.7.6
Fix Version/sSprint 2012-04, Release 2.0.0
ComponentsiOS
Labelsmodule_buttonbar, qe-testadded
ReporterQing Gao
AssigneeStephen Tramer
Created2011-12-05T14:49:29.000+0000
Updated2012-03-14T16:56:22.000+0000

Description

Javescript object has been incorrectly garbage collected in some case.

Repro Steps.

1. Build a project based on the following code snippet and run the project. 2. Touch the first row textfield then continuously click the "next" buttons on the keyboardToolbar for more than 4 times. Expected Result: You should be able to move the focus to the next textfield by clicking the "next" button. Actual Result: The buttons on the toolbar get frozen and you can not switch the focus.
Titanium.UI.setBackgroundColor('#000');
var datasource=[],textFieldArray=[],table,rowId=1,textFieldId= 0;
var win1 = Titanium.UI.createWindow({
	title:'Window',
	barColor:'#808080',

});

var scrollView = Ti.UI.createScrollView({
	top:0,
	bottom:0,
	right:0,
	left:0,
	contentWidth:320,
	contentHeight:'auto',
	layout:'vertical',
	backgroundColor:'#fff'
});

for (i = 0; i <=12; i++) {
	var row = createRows(rowId);
	scrollView.add(row);
	rowId++;
}

win1.add(scrollView);

function createRows(_rowId) {

	var flexSpace = Titanium.UI.createButton({
		systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
	});

	var navButtons = Titanium.UI.createButtonBar({
		labels:['Previous','Next'],
		backgroundColor:'#000',
		top:100,
		style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
		height:25,
		width:'auto'
	});
	var done = Titanium.UI.createButton({
		systemButton:Titanium.UI.iPhone.SystemButton.DONE
	});
	var inputTextField = Titanium.UI.createTextField({
		color : '#ff7c00',
		top : 5,
		height : 50,
		textAlign : 'right',
		width : '25%',
		hintText : '',
		left : '65%',
		right : '8%',
		keyboardToolbar : [navButtons,flexSpace,done],
		keyboardToolbarColor : '#898989',
		returnKeyType : Titanium.UI.RETURNKEY_DEFAULT,
		borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED,
		keyboardType : Titanium.UI.KEYBOARD_NUMBER_PAD,
		font : {
			fontSize : 20,
			fontColor : '#ff7c00',
			fontWeight : 'bold',
			fontFamily : 'Helvetica Neue'
		}
	});
	inputTextField.rowId=_rowId;
	textFieldId = textFieldId + 1;
	inputTextField.id = textFieldId;
	textFieldArray.push(inputTextField);
	//prevent inputTextField from being GCed due to a bug.
	// inputTextField.addEventListener(
	// 'blur', function(e) {
	// });
	navButtons.addEventListener('click', function(e) {
		max = textFieldArray.length;

		if(e.index ===0) { /*Prev Tab*/

			if(	inputTextField.id ===1) {
				done.fireEvent('click');
			} else {
				var rowIndex=inputTextField.rowId-1;
				Ti.API.info("change focus of row: "+ rowIndex );
				changeFocus(rowIndex,0,textFieldArray);
			}
		} else { /*Next Tab*/
			if(inputTextField.id === max) {
				done.fireEvent('click');
			} else {
				var rowIndex=inputTextField.rowId + 1;
				Ti.API.info("change focus of row: "+ rowIndex );
				changeFocus(rowIndex,1,textFieldArray) ;
			}
		}

	});
	done.addEventListener('click', function() {
		for(i=0,j=textFieldArray.length;i<j;i++) {
			var textField =  textFieldArray[i];
			textField.blur();
		}
	});
	
	return inputTextField;
	

}

function changeFocus(_rowIndex,_flag,textFieldArray) {

	//table.scrollToIndex(_rowIndex);
	Ti.API.info("Focus id is: " + _rowIndex);
	textFieldArray[_rowIndex-1].focus();

};

win1.open();

Workaround Method

Define an empty callback function in the "blur" eventlistener to prevent the inputTextField from being GCed.

Comments

  1. Stephen Tramer 2011-12-05

    Almost certainly caused by the same JSCore bug as TIMOB-6438.
  2. Stephen Tramer 2011-12-29

    All JSCore bugs are bumped to high priority, but this may be an endemic problem with the JSCore allocator when it decides it's run out of space and doesn't feel like allocating more pages. If this is the case we should follow standard procedure for reporting 3RD party (and Apple) bugs.
  3. Stephen Tramer 2012-01-03

    Probable JSCore bug to be batched with other JSCore issues during the 1.9.0 timeframe.
  4. Blain Hamon 2012-02-22

    This still happens in latest JSCore build. May be a remember/forget proxy issue instead.
  5. Stephen Tramer 2012-02-23

    Sorry, should have removed the ios-jscore label from this (I think I did?) since I double-checked during testing the new jscore and found out it was still a problem. Still slated for this release though.
  6. Stephen Tramer 2012-02-24

    Removed invalid links as this was not a jscore issue.
  7. Max Stepanov 2012-02-27

    PR https://github.com/appcelerator/titanium_mobile/pull/1504 merged into master.
  8. Wilson Luu 2012-03-14

    Closing bug. Verified fix on: SDK build: 2.0.0.v20120314130253 Titanium Studio, build: 2.0.0.201203132050 xcode: 4.2 Device: iphone 4s (5.0.1)

JSON Source