×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    9

    Dereference objects

    lets go straight to the point. I've read in some articles and it's stated there that "Dereferencing objects" could improve the performance of a j2me application. This is my code :

    public class StartingScreen extends Midlet{

    class MainMenuScreen{
    private Image b[] = {null,null,null};
    }

    private MainMenuScreen mmScreen;
    }

    in order to improve my application which line should i write (1 or 2) :

    1. mmScreen = null;
    or
    2. Image[0] -- Image[2] = null; mmScreen = null;
    3. or is there any other things i should consider?

    I hope i make myself clear, thanks in advance for the suggestions / answers.

  2. #2
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Dereference objects

    imho, stating mmScreen = null creates the pointer to null location.
    yet, stating only mmScreen does not create the pointer, and trying to access it can be more dangerous than trying to access it after stating it to null.
    so i would suggest that either :
    1/ you only declare your variable, without defining it, even to null, but then you have to be very careful and make sure that you define it before you try to access it in any way (on some device, you may have some issues comparing such variable to null)
    2/ you always declare and define to null. (including Image[] b = null; instead, as the way you declare it could lead to the allocation of 3 Images spaces, though it would point to null)

    Yet, what you should consider, is to avoid creating more classes than really necessary. 3-4 classes can usually do a lot.

    Moreover, the dereferencing you are mentionning is probably more about marking the objects you don't use anymore as obsolete, so that the gc can collect them and reallocate the memory.
    Basically it consist of making sure that there is no unused object that you are still refering to. (In your example, it could be as soon as you leave the MainMenuScreen, set it to null if you are not going to come back to it, at least for a while)

    The point basically is to help the gc do his job, avoid wasting memory with useless old objects.

    hope it helps.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    9

    Re: Dereference objects

    do Image[] b = null equals to Image b[] ? sorry im a bit confused about that.
    i have done just the 2nd method. I run one of the menu in the game in my nokia 6600 device and it crashes. whats the limit of the memory for that phone ? 50k or less than that?
    Last edited by abiieez; 2007-01-24 at 13:54.

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Dereference objects

    much more, but there might be several reason to a crash.
    any error message ?

    btw, both methods are equal

Similar Threads

  1. Active objects in EXE second thread
    By inguvaseshu in forum Symbian Networking & Messaging (Closed)
    Replies: 8
    Last Post: 2006-08-10, 05:35
  2. Can not send any Obex Objects to a billionton bluetooth
    By hoy_cpe in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2006-08-01, 07:28
  3. Bubble sort a list of linked objects!
    By hclemson in forum Symbian
    Replies: 2
    Last Post: 2005-05-15, 13:39
  4. panicking active objects
    By kratom in forum Symbian
    Replies: 0
    Last Post: 2003-04-18, 07:20
  5. Replies: 0
    Last Post: 2003-02-27, 20:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×