Why does LoadPicture use lots of memory

Discussion in 'Questions (Windows Mobile)' started by jdrogan, May 11, 2009.

  1. jdrogan

    jdrogan Member Licensed User

    Hi,
    I'm sure this is a n00b question but why does multiple clicks of the button in this code run memory up? It's like memory isn't released after each execution.
    blank.gif is a "blank" gif of 2.33KB

    Sub App_Start
    Form1.Show
    Image1.LoadPicture("blank.gif")
    End Sub


    Sub Button1_Click
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Image1.LoadPicture("blank.gif")
    Return
    End Sub
     
  2. agraham

    agraham Expert Licensed User

    It won't be until the .NET garbage collector runs. Don't worry about memory unless you get an out of memory error. In .NET the memory management is all taken care of for you.
     
  3. jdrogan

    jdrogan Member Licensed User

    Thanks for the reply.
    That's the problem, the app runs out of memory after 1 or 2 clicks on my ppc.
    On the pc it's not a real issue (4g etc.).

    Is there a way to force the garbage collector to run?

    GCCollect in my code just gives a compile error (it thinks CGCollect is a variable)

    Alternatively, is there a way to programmactically make an image visible/invisible? :sign0104:
     
  4. agraham

    agraham Expert Licensed User

    As you didn't post blank.gif I have no idea how big the picture it represents is, but just because the gif is small it doesn't mean the resulting bitmap is. One problem is that the .NET grabage collector thinks that a Bitmap is small because it only takes up a tiny amount of managed memory, but you are probably running out of conventional memory which is where the real bitmap memory is allocated.

    Out of interest how are you managing to compile your application with what I assume is the trial version as you don't appear to be a registered user?
     
  5. jdrogan

    jdrogan Member Licensed User

    Compiling:
    I'm a licensed member (sent a note to support to get my forum status changed).

    I get it now. The "small" gif was really 2 meg and was running out of conventional memory. Works great now.

    Thanks:)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice