Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-6463

iOS:JavaScript Object is incorrectly garbage collected.

    Details

    • Story Points:
      0

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stephentramer Stephen Tramer
                Reporter:
                qgao Qing Gao
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code