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 Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5 picture

OEM Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5

$13.81



DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X  - Made By DELL picture

DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X - Made By DELL

$39.98



NEW VESA ADAPTER PLATE FOR DELL E-SERIES MONITORS - OEM picture

NEW VESA ADAPTER PLATE FOR DELL E-SERIES MONITORS - OEM

$6.00



Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008 picture

Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008

$5.95



Genuine OEM Dell 2375 B2375dnf B2375dfw 110V Fuser fixing N41P2 sku 724-BBCI picture

Genuine OEM Dell 2375 B2375dnf B2375dfw 110V Fuser fixing N41P2 sku 724-BBCI

$94.99



NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL  picture

NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL

$198.22







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