Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15765] Android: TableView - JNI ERROR (app bug): local reference table overflow (max=512)

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-07-21T02:51:14.000+0000
Affected Version/sRelease 3.1.3
Fix Version/sRelease 6.0.0, Release 5.4.0
ComponentsAndroid
LabelsSupportTeam, exalture
ReporterBeau
AssigneeChristopher Williams
Created2013-11-07T18:25:06.000+0000
Updated2017-09-11T18:11:57.000+0000

Description

Problem Description

This code recreates it. Dies with error : "[ERROR][dalvikvm( 840)] JNI ERROR (app bug): local reference table overflow (max=512)"

Test case

//Set the number of table rows for this test
var numberOfTableRowsToTest = 50;
 
 
var vAnswerTable = Ti.UI.createTableView({
   backgroundColor:'#FFFFFF',
   data: [Ti.UI.createTableViewRow({title:'Loading...'})],
   top: 50,
   left: 0
 
});
 
if(numberOfTableRowsToTest < 5){
 
    numberOfTableRowsToTest = 5;
} 
 
var numOfQuestions = numberOfTableRowsToTest / 5;
var numOfAnswers = numOfQuestions * 4;  
var sections = [];
 
for (var i=0;i<numOfQuestions;i++) {  //Loop over questions array
 
        //Question Variables from DB. 
        var questionID = "questionID"+i;
        var question = "Question Content "+i;
        var position = "question position"+i;
 
        //answersArr = questionsArr[i].answersArr; //Answers array. Contains all answer data for this question from DB.
 
        //Create the table section for each Question. Each question plus its answers is a section. 
        var questionTableSection = Ti.UI.createTableViewSection({
            id:i
        });
 
        //Create the table row for questions. 
        var questionRow = Ti.UI.createTableViewRow({
                   //name: "questionRow"+questionID,    
                   name: "questionRow",
                   title: "\n"+(i + 1)+". "+question,
                   font:{fontWeight:'bold',fontSize:25},
                   color:'#000000',
                   touchEnable: false,
                   selectionStyle:'none'
 
        });  
 
        questionTableSection.add(questionRow);//Add the question row to the table section
 
 
 //BOF: Loop over all of the answers for this question. 
        for (var z=0;z<numOfAnswers;z++) {
 
            //Answer Variables from DB. 
            var answerID = "answerID"+z;
            var answerPosition = "answer position"+z;
            var answerContent = "content"+z;
 
 
            //Create the row for this answer.
            var answerRow = Ti.UI.createTableViewRow({
                    id: answerID,
                    height: 75,
                    color:'#000000',
                    questionID: 1+z,
                    sectionID: i, //The number of the current section. Used in click event to determine what section the click happened in.
                    rowID: z      
            });
            //Ti.API.info("Answer Row Created"); 
            //Create the label for displaying the question. 
            var lAnswer = Ti.UI.createLabel({
                text: answerContent,
                textAlign: "left",
                left:0
            });
            //Ti.API.info("Answer Label Created");
 
 
            //Add the answer label to the answer row.
            answerRow.add(lAnswer); 
            //Ti.API.info("Add Answer label to answer row");
 
            //Add the answer row to this the table section
            questionTableSection.add(answerRow);
            //Ti.API.info("Add answer row to question table section");
 
        }//EOF: Loop over all of the answers for this question. 
 
    sections.push(questionTableSection);    
 
 } 
 
 //Add the sections created above to the table view
 vAnswerTable.setData(sections);
 
 
 
for(var i = 0; i < vAnswerTable.data.length; i++){
 
    Ti.API.info("Error here after "+i+" itteratopns outer loop, current section"+ vAnswerTable.data[i]); 
 
        for(var k = 0; k < vAnswerTable.data[i].rowCount; k++) {
            Ti.API.info("Error here after "+k+" itteratopns inner loop, "+i+" itterations Outter loop current section row"+  vAnswerTable.data[i].rows[k]); 
        }
 
}

Extra information (output of the code)

OUTPUT: [INFO][TiAPI ( 840)] Error Hear after 0 itteratopns outer loop, current section[object TableViewSection] [INFO][TiAPI ( 840)] Error Hear after 0 itteratopns inner loop, 0 itterations Outter loop current section row[object TableViewRow] [INFO][TiAPI ( 840)] Error Hear after 1 itteratopns inner loop, 0 itterations Outter loop current section row[object TableViewRow] [INFO][TiAPI ( 840)] Error Hear after 2 itteratopns inner loop, 0 itterations Outter loop current section row[object TableViewRow]

Conversation in the Q&A

Thread Reference: http://developer.appcelerator.com/question/158112/reference-table-overflow-on-select-all-for-tableview-android#comment-193627

Comments

  1. Dwain Maxwell 2014-06-16

    Any update when this issue is going to be resolved? I am currently facing a similar issue where I loop round two sets of tables rows and pick out its children based on an id. During the second loop of the second table it crashes with the same error.
  2. Ingo Muschenetz 2014-06-16

    [~DMaxwell] Does this fail on device? Is there a reason you can't use a ListView instead?
  3. Dwain Maxwell 2014-06-17

    On android it fails on the device and the emulator. Initially two buttons are used to alternate between two tables both having the same functionality. The table has two sections with two different customised rows, with each row having a button. When a button is clicked a new row is inserted above the row with the clicked button. Each row created has a text field and maybe a picker based on which row was clicked from what section. Basically there can be a total of four different table rows. But a user could add more than one of the same row. I then use a nested loop to find the children of each table row so I can find any text fields added. When I find a text field I add validation to that field based on its id. I can loop the first table, when I get to the second table it crashes with the error in this ticket. I will look in to a list view but I still feel I will have to loop the list view to add validation to the text fields.
  4. Ingo Muschenetz 2014-06-17

    [~DMaxwell]THanks for the description. Could you add a screenshot? I think I get what's going on, but a screenshot would be helpful.
  5. Beau 2014-08-14

    Are you unable to recreate the error with the code submitted as the test case? I can confirm that this was/is an error on the device as well as on the emulator at the time the ticket was submitted. You should be able to drop the test case code into app.js and recreate the error.
  6. Sunila 2014-10-18

    Tried with latest master but I don't see any JNI error Android Nexus 4.3
  7. Christian Schmid 2016-02-03

    I have the same Problem when calling Ti.Contacts.getAllPeople() if more than 500 contacts are on the phone. will this bug be likely to get fixed soon? as Ti.Contacts.getAllPeople() is a native method, i don't find any way to build a worksaround :-(
  8. Sandro Lain 2016-04-26

    I faced the same problem using Alloy (SDK 5.2.2) with very structured views. I used Genymotion as emulator with Android 4.4.4. The view code is: {noformat} {noformat}
  9. Kiley Williams 2016-06-08

  10. Christopher Williams 2016-07-20

    So, looking deeper, there may be a couple things here. When we run on emulator we have a flag to determine if we store Java proxies in a global HashMap/table (when on emulator to workaround this issue); or as global references in JNI (when on device where we don't hit this cap). Possible bugs: - I think our detection of whether we're running on an emulator is now outdated. So we're not flipping that boolean on all emulators like we should. - I think we still have a bug when we generate arrays of proxies. I think when we're generating an array of proxies, we don't add each one to the array and delete the local ref immediately after, but try to do so at the end of array creation. So if we have enough elements in the array we hit the max. This is a theory, I need to look deeper to prove it.
  11. Christopher Williams 2016-07-20

    https://github.com/appcelerator/titanium_mobile/pull/8147
  12. Christopher Williams 2016-07-20

    Back ported for 5.4.0: https://github.com/appcelerator/titanium_mobile/pull/8148
  13. Ashraf Abu 2016-07-21

    Both PRs merged.
  14. Lokesh Choudhary 2016-07-21

    Verified the fix. No JNI error occurs on android < 6. Environment: Appc Studio : 4.7.0.201607111053 Ti SDK : 5.4.0.v20160720201924, 6.0.0.v20160721102342 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.5 Appc NPM : 4.2.8-1 Appc CLI : 5.4.0-33 Node: 4.4.4 Nexus 5 - Android 6.0.1 Samsung galaxy S4 - android 4.4.4 Genymotion Emulator : android 4.4.4 , android 5.1.0
  15. Kiley Williams 2016-07-26

    Thanks Chris for fixing this, Ashraf for merging the PRs, and Lokesh for testing it! Our side has tested it as well and has found no issues. I will let you know in the future if anything pops up again, but I am confident that we won't experience any regression.

JSON Source