×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    36

    Question on createImage

    Hi All,

    One quick question:
    If I keep calling createImage in a loop giving it the same image file then will it create a different image in memory each time the loop is executed? Is that a sort of memory leakage?

    sample code:
    -----------
    while (1)
    {
    image = createImage ("/image.png");
    }

    Will this while loop eat up the entire memory at some point of time?

    Thanks in advance
    Asahlot

  2. #2
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Question on createImage

    personally I dont think so, because the image variable is always the same so it will be overwritten...
    if u'd use different image variables, for example :

    image1 = createImage ("/image.png");
    image2 = createImage ("/image.png");
    image3 = createImage ("/image.png");
    image4 = createImage ("/image.png");
    image5 = createImage ("/image.png");
    image6 = createImage ("/image.png");

    then they would all exist parallel to each other...

    I guess u could compare it with :

    int i = 0
    while(true)
    {
    i += 1;
    }

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Question on createImage

    Yes it will eventually consume all memory. And processing time. And the device battery.

    You should never loop infinitely without pausing the thread for some time, to give a chance for other threads to execute. In this case, you are loading the same variable, true, but the previous contents will be hanging in the heap until they are garbage-collected, so if you are looping too fast, gc won't work fast enough.

    What is the use case for this?

    Daniel

  4. #4
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Question on createImage

    hehe,
    ur completely right, how stupid I didnt even think of that and only thought about the memory usage :P

  5. #5
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Question on createImage

    hehe, it's all right. I have just finished writing a book chapter on "Best Practices and Performance" for MIDP applications so I got all this stuff fresh in my mind. Otherwise I may as well have forgotten

    Daniel

  6. #6
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Question on createImage

    hhhmmm...
    interesting, let us know about this book :P

Similar Threads

  1. to LiuXG:continue the createImage question
    By dying in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 1
    Last Post: 2003-06-25, 06:02
  2. Newbie question: What is the call stack?
    By advocatee in forum Symbian C++
    Replies: 2
    Last Post: 2003-06-22, 05:27
  3. Replies: 1
    Last Post: 2003-04-14, 03:14
  4. Replies: 0
    Last Post: 2003-04-07, 09:52
  5. question deleted
    By kiokups in forum General Messaging
    Replies: 1
    Last Post: 2002-09-25, 20:07

Posting Permissions

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