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


37061 - IMPERIAL RAM MODULE -  picture

37061 - IMPERIAL RAM MODULE -

$205.00



RAM MODULE (COMES WITH WIRING HARDNESS) picture

RAM MODULE (COMES WITH WIRING HARDNESS)

$200.00



Tnt Rescue Equipment Hydraulic Ram R-30   724 picture

Tnt Rescue Equipment Hydraulic Ram R-30 724

$240.00



Double Acting Hollow Ram Cylinder (60 Tons - 2

Double Acting Hollow Ram Cylinder (60 Tons - 2") (YG-6050KS)

$549.00



NCR 7616-1301 NCR 72XRT 15

NCR 7616-1301 NCR 72XRT 15" Retail POS Terminal with i3, 8GB Ram 250GB HD No OS

$239.20



Masimo RainbowSET RAM Dual Cable Red 25 LNC-10 10ft/3m 25 pin ref 3906 picture

Masimo RainbowSET RAM Dual Cable Red 25 LNC-10 10ft/3m 25 pin ref 3906

$99.00







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