BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-07-2008, 03:16 AM   #1
lanfong
New Member
 
Join Date: Jan 2008
Model: 7290
PIN: N/A
Carrier: School Project
Posts: 12
Default Working with multiple screens..memory issue!?

Please Login to Remove!

Hi all,


Here's the situation I have.


I have two screens.
[A] is a built-in MainScreen.
[b] is a custom screen that I extends MainScreen with my custom paint.

[A] is my main screen of my app.

I have a menu item that goes to screen [b] called "Detail Screen"

I use pushModalScreen(new BScreen()) to display screen [b]


When I want to go back to screen [A], I hit the "ESC" key and uiApplication
then popScreen(this) ..(the "this" keyword in java) and pushScreen([A])

scr[b] holds an instance of scr[A] so I would be able to push [A] back...


ok then here it comes my problem
If I go from A to B - B to A many many times,the code that executes will be like calling
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())
pushModalScreen(new BScreen())

is it what people usually do when developing in BlackBerry????




What would be the best practice when developing multiple screens???
If anyone has developed multiple screens app, I will be happy to know
what your ideas.
Offline  
Old 12-07-2008, 11:57 PM   #2
joeisom
New Member
 
Join Date: Feb 2008
Model: 8130
PIN: N/A
Carrier: Verizon
Posts: 1
Default

I just jumped on the forums to ask the same question!

If I am correct, whenever you "pop" a screen, the object is no longer used, so the JVM will preform garbage collection on it (eventually).

I have tried something similar to the following, but not sure how "thread-safe" it is. (I'm just learning java, so I'm not an expert in thread-safety yet)

PHP Code:
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class 
MyScreen extends MainScreen 
{    
    private static 
MyScreen _singleInstance null;

    public 
MyScreen() 
    {
        
super();
        
        
// Add Components / Fields Here!
        
        
synchronized(this)
        {
            
_singleInstance this;
        }
    }

    public static 
MyScreen getMyScreen()
    {
        if(
_singleInstance == null)
        {
            
_singleInstance = new MyScreen();
        }
        return 
_singleInstance;
    }

Then replace:
PHP Code:
UiApplication.getUiApplication().pushScreen(new MyScreen()); 
with:
PHP Code:
UiApplication.getUiApplication().pushScreen(getMyScreen()); 
Doing this ensures that you are not constantly creating / destroying screens that do not change.

So, I hope I kind-of answered your question. The JVM takes care of garbage collection on the "pop"ed screens. But you are taking a performance hit by constantly creating and destroying something that may not change frequently.

Anyone have other tips on this?

Last edited by joeisom; 12-08-2008 at 02:12 AM..
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


OEM  IBM Type 5441 WheelWriter 3 1356658 1362400-02 Main Boards Tested Working picture

OEM IBM Type 5441 WheelWriter 3 1356658 1362400-02 Main Boards Tested Working

$49.99



OEM IBM Selectric II Key Tops & Parts picture

OEM IBM Selectric II Key Tops & Parts

$49.95



New 2 Sets of 2 (4) keys total OEM 9952 IBM Keys for Cash Drawers Displays Locks picture

New 2 Sets of 2 (4) keys total OEM 9952 IBM Keys for Cash Drawers Displays Locks

$14.99



Lot of 2 IBM Correctable Ribbon Cassette Black 1299300 NOS Original OEM picture

Lot of 2 IBM Correctable Ribbon Cassette Black 1299300 NOS Original OEM

$12.00



IBM Genuine OEM Printer Filler Wide Credit Card Holder 10N1259 picture

IBM Genuine OEM Printer Filler Wide Credit Card Holder 10N1259

$24.79



NEW Genuine OEM IBM Quietwriter Hi Density Correcting Ribbon 1299635 NOS picture

NEW Genuine OEM IBM Quietwriter Hi Density Correcting Ribbon 1299635 NOS

$19.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.