×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Out Of Memory Error (App Size- 560kb)

    hello everyone!

    My application size is near about 580kb and i am using j2meMicroDB database in it. And very first task of my application is to populate database table from a text file present in image folder. It is working fine but when my text file increase to near about 100kb or more then while loading the data it show "Out Of Memory Error".
    I've seen the Nokia c101 specification which shows : internal memory -10MB.

    I want to in which memory jar file get installed. and what is the Maximum size of jar file we can install?

    I am new in j2me... pls enlighten me on this.

    Thanks..

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    Hi jayantb,

    The .jad and .jar files can be either installed on the phone's memory or on the memory card. However the maximum allowed size for the .jar file is usually much lower than the phone's memory. The heap memory is allocated for java applications, when you launch a midlet. In your case it is 1 MB, so you most likely exhausted it.

    More info regarding hardware characteristics here:

    http://library.developer.nokia.com/i...833C0E2C7.html

    The device specification page, contains detailed information about the maximum sizes of heap memory/jar file for each model (including C1-01), under the memory tab:
    http://www.developer.nokia.com/Devic...cations/C1-01/

  3. #3
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: Out Of Memory Error (App Size- 560kb)

    Quote Originally Posted by jayantb View Post
    hello everyone!

    My application size is near about 580kb and i am using j2meMicroDB database in it. And very first task of my application is to populate database table from a text file present in image folder. It is working fine but when my text file increase to near about 100kb or more then while loading the data it show "Out Of Memory Error".
    I've seen the Nokia c101 specification which shows : internal memory -10MB.

    I want to in which memory jar file get installed. and what is the Maximum size of jar file we can install?

    I am new in j2me... pls enlighten me on this.

    Thanks..
    try by compressing your jar file with obfusscation
    Regards,
    Pradip

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    I've tried everything... rechecked my code. Now situation is :

    Application Size (575 Kb), Text file size which has to be load is (117Kb)

    In Nokia c1-01 (Max jar size: 1Mb, Heap Size: 1Mb) : Showing "Out of Memory Error" While data loading from textfile. After error Jar size is 747Kb.

    Now to Increase Heap Size i've used Nokia 2690.
    In Nokia 2690 (Max jar size: 1Mb, Heap Size: 1Mb) : Showing "Out of Memory Error" While data loading from textfile. After error Jar size is 734Kb.

    Now to increase Max Jar file size i've used External memory card (2Gb free space available) in Nokiac1-01 :
    In Nokia C101 (Max jar size: External Memory(2Gb), Heap Size: 1Mb) : Showing "Out of Memory Error" While data loading from textfile. After error Jar size is 1.2Mb.

    External Memory Card + Nokia 2690 (2Mb Heap Size) :
    In Nokia C101 (Max jar size: External Memory(2Gb), Heap Size: 2Mb) : Showing "Out of Memory Error" While data loading from textfile. After error Jar size is 734Kb.
    .
    .
    .
    .
    Then Finally i've used Nokia E63 (S60, Heap size, Max jar size: Unlimited): Working Fine.
    pls tell me whats going wrong. i've to implement my app in S40 nokia

  5. #5
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    Hi jayantb,

    You problem is not related to the size of the .jar file, but to restrictions regarding the size of the device's heap memory. The heap memory is statically allocated when you application tries to launch and it cannot be expanded with a memory card. C1-01 will always have 1MB and 2690 will always have 2MB of heap memory. Besides your text file, the heap memory stores all of your application's variables and eventually gets full, that's why you get the "Out of Memory Error".

    Generally speaking Series 40 devices lack the resources of the higher end models and MIDlets often run out of memory when trying to read even relatively small files (text files, image files of 90-100KB), so you might want to consider an alternative solution to your implementation design, such as storing user data in a database that you can access over the web:
    http://www.developer.nokia.com/Commu...Using-Java-Web
    Last edited by skalogir; 2011-11-24 at 18:19.

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    Hi skalogir,

    As i stated, in Nokia 2690 heap memory size is 2Mb but still showing the "Out of memory error". I'cant use my web solution, i've made this project for rural area where GPRS connectivity is poor. Thats y am using SMS based solution and storing user data on mobile.

    If 2Mb heap is not enough, that means i need to look up for S60 devices. As i searched no S40 device have more than 2Mb heap size.

  7. #7
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    Hi jayantb,

    Have you considered storing the data in the device's persistent storage (RMS)? This is an alternative for storing data locally, and you can divide your data into records in order to reduce heap memory usage, add the records into the persistent storage and then load only those that are relevant to the current operation.

    More about persistant storage:
    http://library.developer.nokia.com/i...e-summary.html

    An example can be found here:
    http://library.developer.nokia.com/i...132B47309.html

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    Hi skalogir,

    Actually my data is in different language (Hindi Text). Dat is where my RMS code is lacking. While reading data (direct or through stream), it is not displaying proper string. unable to read the text format. plus data amount is huge and need to store in structured manner ...datsy i used J2ME-MICRO-DB database instead of persistent memory.

    Thanks

  9. #9
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    While reading data (direct or through stream), it is not displaying proper string. unable to read the text format
    Have you used the writeUTF method?
    I didn't have any problems displaying Hindi text on the device's screen with the sample code below that writes a record and then reads it:
    Code:
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.EOFException;
    import java.io.IOException;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.rms.RecordStore;
    import javax.microedition.rms.RecordStoreException;
    import javax.microedition.rms.RecordStoreFullException;
    import javax.microedition.rms.RecordStoreNotFoundException;
    import javax.microedition.rms.RecordStoreNotOpenException;
    
    public class RecordBasic extends MIDlet implements CommandListener {
    	RecordStore rms;
    	Form f;
    	Command addRS;
    	Command readRS;
    	Command availableMemory;
    	int recId;
    	
    	protected void destroyApp(boolean unconditional)throws MIDletStateChangeException 
    	{
    		try 
    		{
    			rms.closeRecordStore();
    		} catch (RecordStoreNotOpenException e) {
    			e.printStackTrace();
    		} catch (RecordStoreException e) {
    			e.printStackTrace();
    		}
    	}
        public String get(){
            String result = "";
        	try 
        	{
        		ByteArrayInputStream bais = new ByteArrayInputStream(rms.getRecord(recId));
        		DataInputStream inputStream = new DataInputStream(bais);
        		try 
        		{
        			result = inputStream.readUTF();
        		}
        		catch (EOFException eofe) 
        		{
        		    System.out.println(eofe);
        		    eofe.printStackTrace();
        		}
        	}
        	catch (RecordStoreException rse) {
        	    System.out.println(rse);
        	    rse.printStackTrace();
        	}
        	catch (IOException ioe) {
        	    System.out.println(ioe);
        	    ioe.printStackTrace();
        	}
            return result;
        }
    
        public void set(String data) {
        	ByteArrayOutputStream baos = new ByteArrayOutputStream();
        	DataOutputStream outputStream = new DataOutputStream(baos);
        	try 
        	{
        	    outputStream.writeUTF(data);
        	}
        	catch (IOException ioe) {
        	    System.out.println(ioe);
        	    ioe.printStackTrace();
        	}
        	// Extract the byte array
        	byte[] b = baos.toByteArray();
        	// Add it to the record store
        	try {
        	    recId = rms.addRecord(b, 0, b.length);
        	}
        	catch (RecordStoreException rse) {
        	    System.out.println(rse);
        	    rse.printStackTrace();
        	}
        }
     
        public int left()
        {
        	int output=0;
        	try{
        		output=rms.getSizeAvailable()/1024;
        	}catch(Exception e){}
        	return output;
        }
    	protected void pauseApp() {
    
    	}
    	protected void startApp() throws MIDletStateChangeException 
    	{
    		try {
    			rms = RecordStore.openRecordStore("MyStore", true);
    		} catch (RecordStoreFullException e) {
    			e.printStackTrace();
    		} catch (RecordStoreNotFoundException e) {
    			e.printStackTrace();
    		} catch (RecordStoreException e) {
    			e.printStackTrace();
    		}
    		
    		f=new Form("Record Store");
    		addRS=new Command("ADD",Command.OK, 1);
    		readRS=new Command("READ", Command.OK, 2);
    		availableMemory=new Command("Free memory",Command.OK,3);
    		f.addCommand(addRS);
    		f.addCommand(readRS);
    		f.addCommand(availableMemory);
    		f.setCommandListener(this);
    		Display.getDisplay(this).setCurrent(f);	
    	}
    
    	public void commandAction(Command c, Displayable d) {
    		if(c==addRS)
    		{
    			String message="मानक हिन्दी";
    			set(message);
    			f.append("Added!\n");
    		}
    		if(c==readRS)
    		{
    			f.append("Got:"+get()+"\n");		
    		}
    		if(c==availableMemory)
    		{
    			f.append("Size available: "+left()+" KB\n");
    		}
    	}
    }
    You can also get the remaining size of the heap memory allocated to RMS in bytes. I could get 512 Kbytes available on some Series 40 devices such as the Nokia C3. Given that your text file is 117 Kbytes, that should cover it. It's only a matter of grouping your data when adding your records, so that upon extracting them, you don't retrieve a large number of bytes, that could consume all memory.

  10. #10
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    Hi skalogir,

    Your example is good thanks for this coz i've assumed RMS doesn't support hindi.

    As i explain earlier, i am using J2ME Micro Db, which give me the freedom to create Tabular structure. As i have 25 column and 213 row in my table. How would i store this data in RMS ..??? In RMS, i think, i've to use 'delimiters' like this:

    Record1 = col1+"#"+col2+.....+"#"+col25
    rms.addRecord(Record1).

    If i want to search for a string that situated in 200th row-23rd column. How wud i do this??

    for(int i=0; i<213; i++){
    String str = readRecord();
    String[] arr = removeDelimiter();
    for (int j=0; j<arr.length; j++) {
    // Match the string
    }
    }
    This code reduce the efficiency of searching and other operations as i need to read record , than remove delimiters and match the string.

    Is RMS is a better solution than J2ME Micro Db in such conditon ??

  11. #11
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    What you need can be done by keeping the recId stored in a two dimensional array of integers:
    Code:
    int[][] myarray=new int[200][23];
    A recId is assosiated with each record when you store the record to RMS, so that you can retrieve the record later on, by referencing its recId:

    Storing:
    Code:
    recId = rms.addRecord(b, 0, b.length);
    Retrieving:
    Code:
    ByteArrayInputStream bais = new ByteArrayInputStream(rms.getRecord(recId))
    Now in your case you can add the table's content to RMS in such an order so that the first row, first column is saved first and you keep this record's recID at myarray[0][0]. Then the first row, second column is stored in RMS and its recId is stored in myarray[0][1] and so on.

    When you need to retrieve 3rd row, 19th column, all you have to do is call the get method as shown in the example in my previous post, by passing as recId the value of the array: myarray[2][18]

  12. #12
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Out Of Memory Error (App Size- 560kb)

    are you by any chance also using images in your application ? keep in mind that even small images (as in kilobytes and jpeg/png compressed) will become much bigger as they are converted to a bitmap, which happens all in-memory...
    Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them.

  13. #13
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    Hi skalogir,

    I'll try to use RMS in next version of my application. 1 more question i want to ask. how would i delete a record by id in RMS..?? If i delete a record by id, than i wont able to use that recordId in future. And while searching, if i read that record, it gives error. but j2ME Micro Db have a delete() function, which handle this scenario very well.

    pls suggest how to implement this in rms?

  14. #14
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    Re: Out Of Memory Error (App Size- 560kb)

    Hi Tiger79,

    Sir, U will shout on me after reading this. I am using j2me polish in my project and inside "base" folder i've 40 images that i am using in my project currently. Did u mean all of these images load at once at the time midlet launch and remain in runtime memory??
    Last edited by jayantb; 2011-11-30 at 05:24.

  15. #15
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Out Of Memory Error (App Size- 560kb)

    1 more question i want to ask. how would i delete a record by id in RMS..??
    You can do that by calling the deleteRecord method and passing the recordId as argument to the method.

    You can find more information on this here:

    http://library.developer.nokia.com/i...cordStore.html

    And while searching, if i read that record, it gives error. but j2ME Micro Db have a delete() function, which handle this scenario very well.
    On the same page, you will find that RecordIds are positive numbers starting from 1 and incrementing every time you add a new record. The good news is that if you delete a record, recordIds do no decrease (if that happened then you would have to re evaluate the two dimensional array of integers that acts as a mapping table between your data and the location of your data in the record store).

    So there are many ways you can see whether for example the record with recordId myarray[3][4] does no longer contains valid data (i.e. is erased). Some are explained below:

    1. When you erase the record you don't perform any additional tasks. When you try to read the record with the given recordId, if an InvalidRecordIDException exception is thrown, that means the record has been deleted. You could catch this exception.

    2. When you erase the record, you could change its recordId to 0 (or a negative value). Next time you try to read the already deleted record, if its recordId value is 0 i.e. myarray[3][4]==0, you could abort the read operation because you know the record associated with this recordId is already deleted.

Similar Threads

  1. How can I get the total memory size?
    By eyalmnm in forum Symbian
    Replies: 4
    Last Post: 2012-07-03, 10:54
  2. Replies: 1
    Last Post: 2006-12-07, 02:44
  3. Replies: 6
    Last Post: 2006-09-22, 19:37
  4. Memory - max. MMC size - 3650
    By mackes in forum Symbian
    Replies: 0
    Last Post: 2003-02-27, 06:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×