Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  k700i: out of memory ?!?  (Read 1489 times)
0 Members and 1 Guest are viewing this topic.
Offline Serethos

Junior Member




Java games rock!


« Posted 2004-12-09 09:04:00 »

i have problems getting my midlet working on the k700i. the phone says it's out of memory after a long loading time.
after a few tries i identificated the bad class:
its a class which automatically formatts some text passages.
it only uses local variables and only sends a string array back.

the formatting sequence is as follows:

1  
2  
3  
4  
5  
6  
MidletConstructor
{
         String txt1[] = textFormatter.format(sometextstring);
         String txt2[] = textFormatter.format(anotherString);
         etc..
}


i call this method several times (about 10 times). if i only format the first string, all is ok. another one lets the memory explode (says the phone).
but the class isnt really on my focus cause i tracked the whole thing with the memory monitor (like you can guess the midlet runs flawlessly on emulators).

the k700i seems to have a heap of 100k. at the time, where the first string gets formatted the phone takes 35k.
when the whole game is loaded and main menu gets displayed the heap is up to 53k.

so im not even nearly scratching the limit.
is there any known issue which can cause this error ?
Offline davidaprice

Junior Member





« Reply #1 - Posted 2004-12-09 09:38:17 »

I don't know about known issues in the k700i. But is it possible that your text formatter class uses a very large amount of memory for temporary variables, which aren't in use afterwards? That way you could have a high peak memory usage even though it's low again afterwards.

Another possibility would be that the second string you pass to the text formatter triggers a bug that uses up much more memory than it should (but still not enough to trouble the emulator).
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #2 - Posted 2004-12-09 10:29:08 »

Does your text formatter use String.substring(...)?

substring does not copy the original String, it simply references a subset of the parents char [].

therefor, if you have a huge String, grab a small portion of it (using substring), then discard the original huge String.
The original char [] will not be garbage collected.

Incidentally, the K700 has 512kb of heap, which will expand to upto 1.5mb upon demand.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Serethos

Junior Member




Java games rock!


« Reply #3 - Posted 2004-12-10 12:53:55 »

i hop you have the patience to help me with my now changed problem. i worked on my method to use less memory. it seems to be solved but another strange error occurs. before
i paste the method, i want to share my experiments:

first, my method works on all tested phone without any exceptions or errors. only the k700 and the t610 have problems (but in a slightly different way).

like you will see the core of the method is a tokenizer which goes through all characters and adds their width. if this width
is larger that a given size the character index returns to the last space-character and breaks into a new line.
the problem lies within the variable tokenIndex and its influence to the loop.
if i disable the addition of the char's width (that can happen in many lines) the midlet starts. if i dont do so, on k700 first the constructor loaded without an end.
then i noticed that i used special characters like 'ü' and 'ß' in my sentences.
after replacing them i only get an application error  Grin

i used lots of debug outputs and proofed that no index is used out of the string's boundaries (getCharAt(), substring()).
and my main argument: the identical midlet runs e.g. on my motorola v525.

now for those brave of you, the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
/** 
     * Tries to break a long line of text into several shorter ones, so that
     *  the width of the produced lines is never wider that <i>areaWidth</i>.
     *  The width of the strings is calculated by the width of each appearing
     *  character using the charWidth() method of the given font object.
     *
     *  TODO: method fails if the string has no breaking points (spaces) and
     *        is larger than areaWidth
     *  */

    public String[] tokenizeText(String s, Font font, int areaWidth)
    {
        // valid string ?
       if( s == null )      return null;
        System.out.println("\n\n **** TOKENIZING **** ");
        System.out.println("tokenize: "+s);
        System.out.println("length of string "+s.length());
       
        // contains the new formatted text block, each entry means a text row
       Vector newOrder = new Vector();
        // the string array which is returned by this method as result
       String resultStrings[];
               
        int startToken = 0, lastSpace = 0;
        int currentRowWidth  = 0;
        int row = 0;
       
       
        // checking all characters
       for(int tokenIndex=0; tokenIndex<s.length(); tokenIndex++)
        {
            currentRowWidth+=font.charWidth(s.charAt(tokenIndex));
         
            // marking a space as return point for line break
           if(s.charAt(tokenIndex) == ' ')
                lastSpace = tokenIndex;
           
            // if the width of all checked chars exeeds the boundaries
           // return to the last marking point and access new line (next array field)
           if(currentRowWidth >= areaWidth)
            {
                // creating one row of text, fitting into boundaries
               newOrder.addElement( s.substring(startToken, lastSpace) );
               
                // marking start (and end) of characters to convert
               startToken = lastSpace+1;
                tokenIndex = lastSpace+1;
               
                currentRowWidth = 0;
            }
           
        }
       
        // formatting the remaining chars to row
       newOrder.addElement( s.substring(startToken) );
       
        // convert vector of strings into string array
       resultStrings = new String[newOrder.size()];
        for(int i=0; i<newOrder.size(); i++)
            resultStrings[i] = (String)newOrder.elementAt(i);

        return resultStrings;
       
    }

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (9 views)
2014-08-31 22:59:12

TehJavaDev (22 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (71 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!