×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    quick question pls reply

    hello everyone, just a quick question.

    if for example in one class I created a Image variable holding an image and changed from this class to another using Display.setCurrent(nxtdisplayable);.

    will that image variable automatically set to null and free the memory?

    I really need to know since when I ran my program on an emulator its working fine but when I ran it on N70 the game crashed after going to the main part of the game.

    I tried removing the images used in this part of the game and it ran. But I need those images for the game so how do i solve this problem? Please help.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: quick question pls reply

    Hi,

    AFAIK, no. You must make sure the reference is released and nulled and use the showNotify() and hideNotify() methods to handle that. Besides, the enclosing class must be released as well.

    The Java Garbage Collector will clean only objects that are not referenced anymore but if one ref exists, it will survive.

    Br,
    Juarez Alvares Barbosa Junior - Brazil

  3. #3
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    220

    Re: quick question pls reply

    Hi,

    I think you can do one thing...write a method in your midlet class itself, say loadImages(), that will load the images you require throughout your application.

    next, pass this midlet reference to all the displayable class that you are creating....all the images will be abailable to you..

    here is the dummy code for your midlet-

    public class MyMidlet extends MIDlet{

    ............
    .......

    public void loadImages()
    {
    imageOne=Image.createImage("/images/iconOne.png");
    imageTwo=Image.createImage("/images/iconTwo.png");
    imageThree=Image.createImage("/images/iconThree.png");
    ...........
    }

    }

    next, in your diaplayable class you can have something like-

    class MyCanvas extends Canvas
    {
    .......
    MyMidlet parent;

    MyCanvas(MyMidlet midlet,/*some other parameters*/)
    {
    parent=midlet
    }

    public void handlePaint(Graphics g)
    {
    ...............
    g.drawImage(parent.imageOne,10,20);
    .....................
    }
    }


    Hope this will solve your problem.

    Regards

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: quick question pls reply

    HI There,

    Your image var will not be null and you have to put it null.
    I Hope you dont need that var in next class so you put it null.

    Else if you need that in next class then you can access that var of image through the MIDLET reference.

    And the approach of the amitmishra is better,try tom follow that.Write loading and unloading the resource methods.Code will be simpler and control will be in yr hends.

    public void loadInitealImages ( int gameState )
    {
    try
    {
    switch( gameState )
    {
    case LOGO_STATE:
    logoAndSplashImg[0] = Image.createImage ("/logo.png"); // 1st Image to be appear
    logoAndSplashImg[1] = Image.createImage ("/splash.png"); // 2nd Image to be appear
    backLayer = Image.createImage ("/backGround.png"); // game BackGround
    inGameBackLayer0 = Image.createImage ("/inGameBack0.png"); // In game BackGround
    inGameBackLayer1 = Image.createImage ("/inGameBack1.png"); // In game BackGround
    inGameBackLayer2 = Image.createImage ("/inGameBack2.png"); // In game BackGround

    imgFontSmall_B = Image.createImage ("/font_small_black.png"); // In game small FONT BLACK
    imgFontSmall_G = Image.createImage ("/font_small_gold.png"); // In game small FONT GOLD

    fontBigImage_Black = Image.createImage ("/font_big_black.png"); // In game small FONT BLACK
    fontBigImage_Gold = Image.createImage ("/font_big_gold.png"); // In game small FONT GOLD
    break;

    }
    }

    same for unloading() the images...


    Regards
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Feb 2008
    Posts
    26

    Re: quick question pls reply

    Greetings,

    thanks for all your help everyone.

    Your advices are really a great help in creating my game!

Similar Threads

  1. J2ME L2CAP Quick Question =>>>
    By zinomorph in forum Bluetooth Technology
    Replies: 0
    Last Post: 2005-08-02, 15:08
  2. J2ME RFCOMM Quick Question =>>>
    By zinomorph in forum Bluetooth Technology
    Replies: 0
    Last Post: 2005-08-02, 14:49
  3. Urgent answer pls Firmware & MIDLet 2.0 question ASAP?
    By ManiDCI in forum Mobile Java General
    Replies: 2
    Last Post: 2005-06-26, 15:17
  4. Strange question on 6230
    By DanAvni1 in forum Mobile Web Site Development
    Replies: 1
    Last Post: 2005-04-18, 06:05
  5. Yucca:::::::::: Pls Reply........
    By tech_symbian in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-07-17, 07:24

Posting Permissions

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