B4J Question Image Downloader and memory

Discussion in 'B4J Questions' started by TomDuncan, Aug 7, 2015.

  1. TomDuncan

    TomDuncan Active Member Licensed User

    Hi,
    I have a routines that downloads images from my server to a tableview.
    Each time I call this routine I loose heaps of ram.
    What I assume is the memory used in the creation of the table is not freed before it is loaded again.
    Any thoughts.

    Code:
    tblImages.Items.Clear
        tblImages.SetColumns(
    Array As String("id""Name","Image"))
        
    Dim im As Map
        im.Initialize
        
    If AllImages.IsInitialized Then
            
    If AllImages.Size>0 Then AllImages.Clear
        
    Else
            AllImages.Initialize
        
    End If
        
    ' fill here
        Dim jp As JSONParser
        jp.Initialize(Json)
        
    If jp <> Null Then
            
    Dim mz As Map = jp.NextObject
            
    Dim lst As List = mz.Get("json")
            
    For i = 0 To lst.Size -1
                
    Dim m As Map = lst.Get(i)
                m.Put(
    "updt",0)
                    
    Dim row(3As Object
                    row(
    0) = m.Get("id")

                    
    Dim p As AnchorPane
                    p.Initialize(
    "")
                    p.LoadLayout(
    "EditImage")
                    labFileName.Text = m.Get(
    "filename")
                    edtName.Text = m.Get(
    "name")
                    edtAltName.Text = m.Get(
    "alt")
                    edtName.Tag = i
                    edtAltName.Tag = i
                    cbDelete.Checked = 
    False
                    cbDelete.Tag = i
                    row(
    1) = p
                    AllImages.Add(m) 
    ' add info to list
                    Dim img As ImageView
                    img.Initialize(
    "me")
                    im.Put(img, Serverlink & 
    "/images/" & m.Get("filename"))
                    row(
    2) = img   
                    tblImages.Items.Add(row)
            
    Next
            
    Dim id As ImageDownloader
            
    id.Initialize
            
    id.Download(im)

            tblImages.SetColumnWidth(
    0,0)
            tblImages.SetColumnWidth(
    1,300)
            tblImages.SetColumnWidth(
    2,tblImages.Width - 320)
            tblImages.Visible = 
    True
    Tom
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    ImageDownloader does cache the downloaded images in memory.

    However you are recreating the ImageDownloader each time so the references will be released.

    Do you eventually get an out of memory error?
     
  3. TomDuncan

    TomDuncan Active Member Licensed User

    Yep, sure did. Surprised me.
    Had a look in the task manager and lost heaps each time I selected that tab.
    What would happen if I re create it each time?
    Tom
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You need to find which component hold references to the "old" images. Try to recreate the TableView each time and see whether it solves this.

    Another thing that you should try is to use the same ImageDownloader and clear its cache at some point (make the cache map a public variable).
     
  5. TomDuncan

    TomDuncan Active Member Licensed User

    Will have a look in the morning. But yes a new table view each time is the easiest way.
    Tom
     
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