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
New Developer
Timinator
Posts: 5
Registered: ‎07-14-2008
My Device: 8300
Accepted Solution

getFree() returning 0

I'm fairly new at this.  Trying to obtain the amount of free memory with the following code, but the result is 0.  Any ideas?  JDE 4.5,8300 Simulator with 4.2

 

 

/*
 * MemMark.java
 */
// imports
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.MemoryStats.*;


//extend the UiApplication
public class MemMark extends UiApplication
{
    public static void main(String[] args)
    {
        //instance the app & start event thread
        MemMark myApp = new MemMark();
        myApp.enterEventDispatcher();
    }
    public MemMark()
    {
        //show the launch screen
        pushScreen(new LaunchScreen());
    }
}

//Create the launch screen, extend MainScreen
final class LaunchScreen extends MainScreen
{
    public LaunchScreen()
    {
        //invoke the MainScreen constructor
        super();
        //get the current free memory
        MemoryStats ms = new MemoryStats();        
        int m = ms.getFree();
        //add the title
        LabelField title = new LabelField("MemMark", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        //add text to the screen
        add(new RichTextField("Available memory:"));
        add(new RichTextField(String.valueOf(m)));
    }
    //override onClose() with exiting msg
    public boolean onClose()
    {
        Dialog.alert("Exiting...");
        System.exit(0);
        return true;
    }
}

 

 

 

JDE 4.5
Codito Ergo Sum
Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: getFree() returning 0

JDE 4.5 and Sim 4.2? 

 

Just a thought, but I think the Sim and JDE need to match (or Sim can be later), in the same way as for devices - see  

What Is - Appropriate version of the BlackBerry JDE knowledge base article for assistance with choosing the correct version of the BlackBerry JDE for your environment:

http://tinyurl.com/36w5sx

Please use plain text.
New Developer
Timinator
Posts: 5
Registered: ‎07-14-2008
My Device: 8300

Re: getFree() returning 0

Nice catch.  However I've also tried thus under a 4.5 simulator and on my 8300 with the 4.5 beta, with the same results.  getFree() still returns 0. 
JDE 4.5
Codito Ergo Sum
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 792
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Bell

Re: getFree() returning 0

The Memory class provides MemoryStats objects that contain the information you are looking for: http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/system/Memory.html

 

Tim

Tim Windsor
Application Development Advisor II
Please use plain text.
New Developer
Timinator
Posts: 5
Registered: ‎07-14-2008
My Device: 8300

Re: getFree() returning 0

Changing the import to ...system.memory.* and then using: int m = Memory.getFlashFree(); did the trick.  Thanks for the assist.
JDE 4.5
Codito Ergo Sum
Please use plain text.