×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Question Confused about phone limitations

    Hello everybody. I'm developing a game under Netbeans but I'm quite confused about phone limitations. I'm adding many big sprites and still runs fine in the emulator, but when I transfer it to a mobile phone (Nokia 5610) it shows "Out Of Memory Error".

    So I'm quite confused about the game limitations, how can I know the amount of memory consuming and what are the average phone memory limits?

    Thank you very much!

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Confused about phone limitations

    Hi,

    You can check these article:
    How to find out the free memory in Java ME
    How to find out the total memory in Java ME

    And you can check phone-specific memory sizes on the phone's specification page:
    http://www.forum.nokia.com/devices/5610_XpressMusic

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Re: Confused about phone limitations

    Thank you very much, I understand it more, but I'm still confused. I print FreeMemory and TotalMemory in the screen, and TotalMemory stays but FreeMemory goes down continually, and when it reaches 0 starts counting again from the start ¿?

    also I've played the game in the phone deleting sprites and testing until it worked. Sadly only runs if I delete almost all the sprites.

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Confused about phone limitations

    Hi,
    As you have understand it that you can not load as many images as you think.Also as bogdan.galiceanu described the free/used/total memory idea.He has also give the idea about the full specifications about the handsets.Therefore you have to think first, when you actually loading an image.

    So the idea would be to fix your OOM problem.

    1.First load the images when you need it at the exact time.
    2.Once you have done with it and you dont need this. mark it null,
    3.Same idea must be applicable for the other object/variables
    4.Make sure that you are not initializing any thing in loop.
    5.Size of images is also an important factor.

    Check everything in memory monitor so that at what exactly time you are getting what cost to the heap.

    The more points that i can left to put here can be found here..
    http://wiki.forum.nokia.com/index.ph...Best_Practices

    I think that if you will follow these points then you can fix the OOM issue.

    Any query will be answered.
    Thanks
    Last edited by raj_J2ME; 2008-10-18 at 07:25.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Regular Contributor
    Join Date
    May 2008
    Posts
    50

    Re: Confused about phone limitations

    Quote Originally Posted by endless_dark View Post
    Hello everybody. I'm developing a game under Netbeans but I'm quite confused about phone limitations. I'm adding many big sprites and still runs fine in the emulator, but when I transfer it to a mobile phone (Nokia 5610) it shows "Out Of Memory Error".

    So I'm quite confused about the game limitations, how can I know the amount of memory consuming and what are the average phone memory limits?

    Thank you very much!
    Use tiled image to minimize amount of memory use.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Re: Confused about phone limitations

    Thank you for the answers, clearly there is a memory leak in my code, but I can't find where, every game cycle the memory decreases, so I've commented most of the code but still it's decreasing ¿?¿?

    Here is my run() code without the commented parts:

    Code:
      public void run() {
            while (true) {
                
            Graphics g = getGraphics();
            this.Helice.nextFrame();
            
            totalMemory = runt.totalMemory();
            otraMemory = runt.freeMemory();
    
            g.setColor(0xFFFFFF);
            g.fillRect(0,0,240,320);
            this.lm.paint(g, 0, 0);
            g.setColor(0x000000);
            g.drawString(""+totalMemory,30,5,Graphics.HCENTER|Graphics.TOP);
            g.drawString(""+otraMemory,30,15,Graphics.HCENTER|Graphics.TOP);
            //i=i+1;
            flushGraphics(0, 0, this.getWidth(), this.getHeight());
    
                try {
                    Thread.sleep(20);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
            }
    Probably is some easy issue that I still don't know because of my noobishm but I still can't wonder what is.

  7. #7
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Confused about phone limitations

    Hi,
    Hey I think i told you most of the points that are primary factors for the OOM issue.One point i forget at the time of my last post.However thats the points here I found.That is also a main reason for memory leak.

    Please note that getGraphics() never be called inside the run method.Put this line inside the constructor and see the effect.I am sure that this time you will fix you problem OOM.
    Please note the comments I have put in you run() method.
    public boolean isAppRunning = false;
    public void run()
    {
    while (isAppRunning)
    {
    // Dont rather never call this method in run..never..
    Graphics g = getGraphics();
    this.Helice.nextFrame();

    totalMemory = runt.totalMemory();
    otraMemory = runt.freeMemory();

    //try to paint this stuff just once...check the above lines I have write
    g.setColor(0xFFFFFF);
    g.fillRect(0,0,240,320);
    this.lm.paint(g, 0, 0);
    g.setColor(0x000000);
    g.drawString(""+totalMemory,30,5,Graphics.HCENTER|Graphics.TOP);
    g.drawString(""+otraMemory,30,15,Graphics.HCENTER|Graphics.TOP);
    //i=i+1;

    flushGraphics(0, 0, this.getWidth(), this.getHeight());

    try
    {
    Thread.sleep(20);
    }
    catch (InterruptedException ex)
    {
    ex.printStackTrace();
    }
    }
    }



    I this time also wana highlight a point is that if you are working with CANVAS,then call the repaint() on every keypressed.In turn repaint() will call the paint() and so you rendering will be just once..and not repeatedly.

    If you need then I can provide the Code Framework to you.

    Hope these lines can help you in any means,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Re: Confused about phone limitations

    Thank you! The getGraphics issue was a big mistake, I thought my code would work now but saldly there is still a memory leak, I have minimized even more my code and now its reduced to this:

    Midlet.java
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class Midlet extends MIDlet {private MiGameCanvas gameCanvas;
        private Thread t1;
        private Display d;
        
        public void startApp() {
            this.gameCanvas = new MiGameCanvas();
            this.t1 = new Thread(gameCanvas);
            t1.start();
            d = Display.getDisplay(this);
            d.setCurrent(gameCanvas);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
            this.gameCanvas.stop();
        }
    }
    MiGameCanvas.java:
    Code:
    import java.io.IOException;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.game.GameCanvas;
    
    /**
     *
     * @author endlessdark
     */
    public class MiGameCanvas extends GameCanvas implements Runnable{
       
        public boolean isAppRunning = false;
        Graphics g;
        Runtime runt=Runtime.getRuntime();
        long totalMemory;
        long freeMemory;
        
        
    public MiGameCanvas() {
         super(true);
          try {
               this.setFullScreenMode(true);
               this.init();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
        
        //Inicio
        private void init() throws IOException {
            isAppRunning=true;
            g=getGraphics();
        }
        
        public void stop(){
        }
        
        
        public void run() {
            while (isAppRunning) {
            paint(g);
            flushGraphics(0, 0, this.getWidth(), this.getHeight());
            totalMemory = runt.totalMemory();
            freeMemory = runt.freeMemory();
    
                try {
                    Thread.sleep(20);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
            }
        
       public void paint(Graphics g){
            g.setColor(0xFFFF00);
            g.fillRect(0,0,240,320);
            g.setColor(0x000000);
            g.drawString(""+totalMemory,30,5,Graphics.HCENTER|Graphics.TOP);
            g.drawString(""+freeMemory,30,15,Graphics.HCENTER|Graphics.TOP);
            flushGraphics(0, 0, this.getWidth(), this.getHeight());};
    }
    I'm quite new in j2me so the code is based on a game example,I think I understand every line. Any clue?

    About the repaint() method, I have been googling for a while but I don't know exactly how to use it.
    It should replace the paint and the flushGraphics lines?

    Thank you for helping me!

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Confused about phone limitations

    Hi,
    Its nice to hear that the previous post help you make your code robust.

    I also told you one point that dont call the paint() inside run()..ok...What you can do is just at the end of keyPressed() put repaint().And remove flushGraphics() from the same.

    I hope you understand it ..what I wana explain.
    Hope this post can help you..is this ??
    Thanks and Regards
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    5

    Re: Confused about phone limitations

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Its nice to hear that the previous post help you make your code robust.

    I also told you one point that dont call the paint() inside run()..ok...What you can do is just at the end of keyPressed() put repaint().And remove flushGraphics() from the same.

    I hope you understand it ..what I wana explain.
    Hope this post can help you..is this ??
    Thanks and Regards
    Nice to hear from you again. But putting repaint() at the end of KeyPressed() would paint the image only when the user press a key right? If I'm doing a game, the enemies for example, should move independently of what the main character moves or not.

    Edit: I have tested the demo game memory that comes with netbeans again and says it has a memory leak too. So assuming that that one is perfect. I suppose my method (totalMemory and FreeMemory) is bad done and that's why it says my game has a memory leak still.
    Last edited by endless_dark; 2008-11-01 at 12:41.

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Confused about phone limitations

    Hi,
    Yeah you are right and that even the basic thing in games..
    Then no issue..you go with the last post.Please check that where and why the memory leakage is there.You can use memory monitor in order to check the same..and the exact time of OOM issue.

    One more thing you have write flushGraphics(0,0,getWidth(),getHeight()); on multiple places...dear just put this line once...I will write you run() again.here it is -


    public void run()
    {
    while (isAppRunning)
    {
    paint(g);
    totalMemory = runt.totalMemory();
    freeMemory = runt.freeMemory();

    try
    {
    Thread.sleep(20);
    }
    catch (InterruptedException ex)
    {
    ex.printStackTrace();
    }
    flushGraphics(0, 0, this.getWidth(), this.getHeight());
    }
    }
    keep one thing in mind that flushGraphics(a,a,a,a) must be just once throughout the code...ok

    Let us know what more issue you still have in the code.
    Thanks,
    Last edited by raj_J2ME; 2008-11-01 at 12:35.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

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

    Re: Confused about phone limitations

    it seems like a little problem I've had also,
    use memorymanager to see which parts of the code are continuesly growing in size...
    just for the fun, comment away the two strings (free memory and totalmemory) which are displayed on the canvas, u might find out it will grow a lot less...
    for osme reason I had a memory leak there the last time i tried something like u are doing now...

  13. #13
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Confused about phone limitations

    Hi Tiger,
    All these points I have tested ..
    Previously I was facing the same problem.

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Nokia Gamer (GamR) - concept phone
    By tgm91 in forum General Development Questions
    Replies: 4
    Last Post: 2008-10-01, 21:34
  2. OMA DRM media transfer using PC to Phone using USB
    By venky123 in forum Digital Rights Management & Content Downloading
    Replies: 1
    Last Post: 2008-08-13, 03:02
  3. Replies: 2
    Last Post: 2008-05-17, 23:29
  4. Asterisk REregister failing
    By kolbi-nokia in forum VoIP
    Replies: 6
    Last Post: 2007-08-15, 19:13
  5. 7610 Contacts - Formatted Phone Numbers
    By padlon in forum General Development Questions
    Replies: 2
    Last Post: 2004-11-12, 19:02

Posting Permissions

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