Record update with RecordStore.setRecord() fails in Series 40 (Known Issue)
Article Metadata
Compatibility
Platform(s): Series 40 3rd Edition (initial release), FP1, FP2
Series 40 5th Edition (initial release)
Series 40 5th Edition (initial release)
Article
Created: User:Technical writer 1
(21 Aug 2008)
Last edited: hamishwillee
(05 Jul 2012)
Description
RecordStore.setRecord() fails to reuse the existing reserved memory, resulting in 'Out of Memory exception' application error notification or the program exiting directly without any notification at all.
How to reproduce
- Implement a test MIDlet using the following code:
-
import javax.microedition.midlet.*;
import javax.microedition.rms.RecordStore;
import javax.microedition.lcdui.*;
public class ErrorDemo extends MIDlet {
//.. pauseApp() and destroyApp() excluded for code brevity
protected void startApp() throws MIDletStateChangeException {
boolean newrun = false;
Form f = new Form("Debug");
Display.getDisplay( this ).setCurrent( f );
try {
f.append("Starting...");
RecordStore r = RecordStore.openRecordStore( "dummy" , true );
int cntr, cntr2;
byte[] empty = new byte[512];
if( r.getNextRecordID() < 2 ) { // empty RMS?
newrun = true;
cntr = 1;
while( r.getSizeAvailable() > 1024 ) {
r.addRecord(empty, 0, 512); // Fill the RMS
cntr++;
}
} else cntr = r.getNextRecordID() - 1;
f.append( "Replacing those records" );
StringItem i = new StringItem( "Record No", "" );
f.append( i );
// Replacing all of the records
for( cntr2=1; cntr2<cntr; cntr2++ ) {
i.setText( String.valueOf( cntr2 ) );
if( !newrun ) Thread.sleep(1000);
r.setRecord(cntr2, empty, 0, 512);
}
} catch( Exception e ) {}
f.append("Done"); // Record (re)placing finished.
try { Thread.sleep(5000); } // Waiting for a while before exiting the MIDlet.
catch( Exception e ){}
notifyDestroyed();
}
}
-
- Launch the MIDlet, let it write the records, and exit the MIDlet.
- Launch the MIDlet again. The described issue occurs.
Solution
This issue has been fixed starting from Series 40 5th Edition, Feature Pack 1.

