Images and memory

wolfgang

Member
Licensed User
Longtime 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
B4X:
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?
 

agraham

Expert
Licensed User
Longtime User
After a while I get a problem with my RAM (2GB).
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?
 

wolfgang

Member
Licensed User
Longtime User
Hi agraham,
I have another reference to imagelist because I draw direct on this image. Reference is:
B4X:
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):
B4X:
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.
 

wolfgang

Member
Licensed User
Longtime 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.
 
Top