Android Question How to free up memory?

Sganga61

Member
Licensed User
Hi
I need to free memory to show a large number of images

Here follow some samples I try to explain:

First example:
For i = 1  To 100
    PROTOCOL_FASE.Bitmap = LoadBitmapSample(Path , filename, 1360dip, 690dip)
Next
With the above code about after 10 load images (same image) the program crash due to end of memory


Second example:
For i = 1 To 100
       PROTOCOL_FASE.RemoveView
       PANEL_PROTOCOL.addview(PROTOCOL_FASE,0dip,3dip,1360dip,690dip)
       PROTOCOL_FASE.Initialize("")
       PROTOCOL_FASE.Bitmap = LoadBitmapSample(Path, filename, 1360dip, 690dip)
Next
Same problem

Third example:
For i = 1 To 100
      Dim LIMAGE As Bitmap
      LIMAGE.Initialize(Path, filename)
      PROTOCOL_FASE.Initialize("")
      PROTOCOL_FASE.Bitmap = LIMAGE             
Next
Same problem

There is a way to discard unused images, unload images or free up the memory?
I need to show (sequentially) about 100 images of 500Kb each.
Some suggestion?
 

Erel

Administrator
Staff member
Licensed User
1. The file size is (mostly) meaningless. The bitmap dimensions matters.
2. Unreferenced bitmaps are released automatically, however it will not happen immediately.
3. There is never a good reason to load 100 large images. You cannot show them at once anyway.

Complicated example that shows an endless number of images: https://www.b4x.com/android/forum/threads/b4x-b4xpages-pleroma-mastodon-client.119426/#content

Simpler example based on BitmapsAsync: https://www.b4x.com/android/forum/threads/b4x-bitmapsasync.119589/
 

Sganga61

Member
Licensed User
Thank you Erel.
My examples don't explain very well what I need: I need to show (sequentially 100 images). In the above examples the PROTOCOL_FASE is an imageview.

What is the best solution to show (sequentially and every second) 100 images?

Thanks again
 

Sganga61

Member
Licensed User
But it is exactly what I do.... but after a lot of images I get a memory fail...
I note that after about one minutes the memory is free by Android background service....but I can't wait this time.
 
Top