Images and memory

Discussion in 'Questions (Windows Mobile)' started by wolfgang, Feb 23, 2008.

  1. wolfgang

    wolfgang Member Licensed User

    Hi,
    I have an app where maps will be displayed. Before I show the map it will be stored in an imagelist an than displayed with the imagelib
    Code:
    drawer.DrawImage1(ImageList1.Item(0),rectSrc.Value,rectDest.Value,false)
    When this map is "finished" a new map will be opened. The imagelist will be cleared and the new map uses index 0 again and so on. Looking at the taskmanager the memory increases very fast. I feel that the new map doesn’t replace the old one; the new will be added to the video memory. After a while I get a problem with my RAM (2GB). How can I delete the old images in the video memory?
     
  2. agraham

    agraham Expert Licensed User

    Can you describe the problem you get with your RAM? The .NET Garbage Collector should be looking after reclaiming memory once you have finished with it. You don't have another reference to each image, other than the ImageList, which might be making the GC think the memory is still in use do you?
     
  3. wolfgang

    wolfgang Member Licensed User

    Hi agraham,
    I have another reference to imagelist because I draw direct on this image. Reference is:
    Code:
    track.New2(ImageList1.Item(0),B4PObject(5))
    and I found that the reference has to be set again after an new images was loaded. But I can't find a command to delete or dispose a drawer object. I have had the same problen on the device and I catched it with an error handler and repeated deleting imagelist and problem was solved. This is the part the error occurs on PC (after a lot of loadings, but always index 0):
    Code:
    Sub btdel_Click
       
    If Not(tbtrack.Text = "enter track"Then
          
    If Msgbox("Delete current track/trace?","Delete",cMsgBoxYesNo,cMsgBoxQuestion) = cYes Then
             ImageList1.Clear
             ImageList1.Add(OpenDialog1.File)
             track.New2(ImageList1.Item(
    0),B4PObject(5))
    .
    .
    .
    Sometimes I reload the same file to correct some wrong drawings.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You should use track.Dispose.
    Before initializing it again you will need to add it with AddObject("track","Drawer").
     
  5. wolfgang

    wolfgang Member Licensed User

    track.Dispose?

    Thank you Erel,
    that's what I'm looking for but I can't find it. Are there other undocumentd commands which would be very usefull?
    I'll give it a try.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    All objects support the Dispose method.
    It is noted under Main Help - External Libraries.
     
Loading...