Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified
Accepted Solution

SQLITE Out Of Memory Error

[ Edited ]

Hi All,

 

I know there are a few threads about this but they appear to be dead. I have attached a very simple and crued application hightlighting my problem.  Click the button and it will start the transactions. 

 

The problem im having is i am getting large amounts of transaction (batches of  250 transactions) from a server to be applied to a database, inserts updates deletes etc.    It works for a while but will then blow with the out of memory exceptions.  The number of transactions can be reduced but even doing 1 transaction per batch will result in the error.

 

The application is doing to be used for 5.0 devices and higher any help would be greatly appreciated. 

 

Cheers

 

 PS.  I no there is suggestions of using System.gc() but that will that not have major problems on the performs. 

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: SQLITE Out Of Memory Error

You created a bunch of statements each time you call the execute method. Test change your fieldChanged event to :

public void fieldChanged(Field field, int context) {
	try {
	    database.beginTransaction();
        statement = database.createStatement("INSERT INTO TEST (ID, VALUE) VALUES(?,?)");
        statement.prepare();
		
		label.setText("INSERTING...");
		StringBuffer sb =new StringBuffer();
		for(int i = 0; i < 100000; i++) {
		  sb.append("Value ").append(i);
		
		  st.bind(1, sb.toString());
          st.bind(2, i);
          st.execute();
          st.reset();
		  
		  sb.setlength(6) ; // "Value " length
		}
		st.close();
	    database.commitTransaction();
		database.close();
	  } catch (DatabaseException e) {
		 label.setText(e.getMessage());  
		e.printStackTrace();
	}
}

 HTH

Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified

Re: SQLITE Out Of Memory Error

[ Edited ]

Ok i will try that but what if the statements change tables?

 

Would i have an extra variable inside the statement then for the table name like

INSERT INTO ?  VALUES(?, ?) etc

 

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: SQLITE Out Of Memory Error

I think you can not do that. Instead could be something like this:

StringBuffer sb = new StringBuffer(1024);
sb.append("INSERT INTO ").append(tableName);
sb.append(" VALUES(?, ?) ");
String sql = sb.toString();

 

Maybe you can use a Hashtable to store the fieldname and fieldtype in order to do the field binding and generate the needed "?" in the sql insert statement.

Developer
Posts: 43
Registered: ‎08-26-2010
My Device: Not Specified

Re: SQLITE Out Of Memory Error

Hi thanks for the suggestion, i have tried it in the test project and it works, However i tried that in the main project and it failed which leads me to believe their was another problem,

I discovered that there was a scenerio where one of the statements was not being closed off which mean the object was never being destroyed.

Thanks for your help in highlighting this.