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


Vintage V-Mac Industries Inc. Pipe Threader Vosper Drophead Threader - READ picture

Vintage V-Mac Industries Inc. Pipe Threader Vosper Drophead Threader - READ

$199.00



Vintage Mac Warehouse  3.5” Floppy Disk Solar Powered Calculator Company Swag picture

Vintage Mac Warehouse 3.5” Floppy Disk Solar Powered Calculator Company Swag

$66.60



Vintage MAC Knife Japan 4.75

Vintage MAC Knife Japan 4.75" Folding Lock Blade Knife Chef Pocket Knife Utility

$224.99



Vintage MAC Tools UVEX Adjustable Safety Glasses Motorcycle Mechanic Lawnmower picture

Vintage MAC Tools UVEX Adjustable Safety Glasses Motorcycle Mechanic Lawnmower

$55.24



Vintage Mac Tools AW343 Series 1/2 Pneumatic Impact Driver  picture

Vintage Mac Tools AW343 Series 1/2 Pneumatic Impact Driver

$40.00



Vintage VTG A. W. Mack 122387 Large Industrial Fuse Puller 100 Amp - 600 Amp picture

Vintage VTG A. W. Mack 122387 Large Industrial Fuse Puller 100 Amp - 600 Amp

$104.99







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