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


Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C picture

Lot of OEM APPLE iPAD LCD And White Front Glass Replacement 6091l-1402C

$17.99



Genuine OEM Apple LG Display LM270WQ1 (SD)(B3) iMac Thunderbolt Display 27

Genuine OEM Apple LG Display LM270WQ1 (SD)(B3) iMac Thunderbolt Display 27" LCD

$168.99



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$40.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$45.90



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$45.90



Genuine 99.5Wh OEM A1618 Battery for Apple MacBook Pro 15” Retina A1398 Mid 2015 picture

Genuine 99.5Wh OEM A1618 Battery for Apple MacBook Pro 15” Retina A1398 Mid 2015

$45.80







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