Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2735] Android: ScrollView does not allow more than 512 elements

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2012-07-31T05:44:48.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, scrollview
ReporterDominik Spengler
AssigneeShak Hossain
Created2012-07-25T07:05:32.000+0000
Updated2016-03-08T07:47:37.000+0000

Description

I am trying to add more than 500 elements into a ScrollView from a db with a loop on Android.The app always crashes with a little more than 500 elements added with the following error message:
D/dalvikvm( 8296): GC_CONCURRENT freed 1200K, 23% free 7569K/9799K, paused 2ms+31ms
E/dalvikvm( 8296): JNI ERROR (app bug): local reference table overflow (max=512)
W/dalvikvm( 8296): JNI local reference table (0x21e410) dump:
W/dalvikvm( 8296):   Last 10 entries (of 512):
W/dalvikvm( 8296):       511: 0x413d7630 java.lang.String "fontWeight"
W/dalvikvm( 8296):       510: 0x413d75d0 java.util.HashMap
W/dalvikvm( 8296):       509: 0x413d7590 java.lang.String "font"
W/dalvikvm( 8296):       508: 0x413d7320 java.util.HashMap
W/dalvikvm( 8296):       507: 0x413d7308 java.lang.Object[] (1 elements)
W/dalvikvm( 8296):       506: 0x413d7298 java.lang.String "app://ui/common/... (29 chars)
W/dalvikvm( 8296):       505: 0x413c89d8 java.lang.String "50dp"
W/dalvikvm( 8296):       504: 0x413759d0 java.lang.String "50dp"
W/dalvikvm( 8296):       503: 0x41337138 java.lang.String "50dp"
W/dalvikvm( 8296):       502: 0x41377488 java.lang.String "50dp"
W/dalvikvm( 8296):   Summary:
W/dalvikvm( 8296):         1 of java.lang.Object[] (1 elements)
W/dalvikvm( 8296):       507 of java.lang.String (507 unique instances)
W/dalvikvm( 8296):         2 of java.util.HashMap (2 unique instances)
W/dalvikvm( 8296):         1 of org.appcelerator.kroll.runtime.v8.V8Runtime
W/dalvikvm( 8296):         1 of org.appcelerator.titanium.proxy.ActivityProxy
E/dalvikvm( 8296): Failed adding to JNI local ref table (has 512 entries)
It seems to be an Android specific problem with the local references in some JNI call not deleted. Unfortunately I can't test it on an iPhone.

Comments

  1. Davide Cassenti 2012-07-31

    Hello, What kind of elements are you adding? I tried adding 1000 labels, and it works fine on my device (Samsung Galaxy S2), as well as on the Emulator v4.0.3 and v2.3.3. There might be a memory issue, if you are adding complex elements to the view; can you post a sample code?
  2. Dominik Spengler 2012-08-04

    Hi, thanks for your reply. I thought about it being a memory issue as well, but in that case the JNI error seems a bit wierd. My setup is a bit more complicated as I add two labels and an image to the ScrollView 500+ times. However I also get this error when adding only labels. I am using the following code to add elements:
       // function to create row elements. To keep it shorter this snippet only adds one label as this does not work either.
       function makeRow(product) {
       	var row = Ti.UI.createView(product);
       
       	row.height = '50dp';
       	var text = Ti.UI.createLabel({
       		text : product.title,
       		row : row,
       	});
       
       	text.addEventListener('click', function(e) {
       		self.fireEvent('itemSelected', detailFunction(row));
       	});
       	return row;
       };
       
       // db loop
       var db = Ti.Database.open(Ti.App.Properties.getString('db-name'));
       var products = db.execute('SELECT name FROM products ORDER BY name ASC');
       
       Ti.API.log('starting to load DB');
       while(products.isValidRow()) {
       	var product_name = products.fieldByName('name');
       
       	var row = {
       		title : product_name,
       	};
       	scrollView.add(makeRow(row));
       	products.next();
       }
       products.close();
       db.close();
       Ti.API.log('finished loading DB');
       
    It has been simplified but I can confirm the above code not working neither on the 2.3.3 emulator nor on the 4.0.3 emulator. I am using Android SDK version 2.2.
  3. Mostafizur Rahman 2013-12-10

    Hello, I tested this issue with the test code below. I can’t reproduce this issue in Ti SDK 3.1.3GA. Please install the latest SDK and test your app. If you continue to get error, please send us a test case with steps to reproduce.

    Testing Environment:

    Ti CLI 3.3.0 Titanium SDK: 3.1.3.GA Android Device 2.3.3

    Test Code

    app.js
        function makeid() {
       	var text = "";
       	var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
       
       	for (var i = 0; i < 15; i++)
       		text += possible.charAt(Math.floor(Math.random() * possible.length));
       
       	return text;
       }
       
       var win = Ti.UI.createWindow({
       	backgroundColor : 'white',
       	exitOnClose : true,
       	fullscreen : false,
       	title : 'ScrollView Demo'
       });
       
       var scrollView = Ti.UI.createScrollView({
       	contentWidth : 'auto',
       	contentHeight : 'auto',
       	showVerticalScrollIndicator : true,
       	showHorizontalScrollIndicator : true,
       	layout : 'vertical',
       });
       
       for (var i = 0, j = 550; i < j; i++) {
       
       	scrollView.add(Ti.UI.createLabel({
       		text : makeid() + ' ' + i,
       		color : '#000',
       		height : 40,
       	}));
       
       };
       win.add(scrollView);
       win.open();
       
       

    Steps to Test

    1. Create a new project 2. Update app.js file 4. And run this project with testing environment

    Expected Result

    550 rows will display on the screen Thanks

JSON Source