Android Question [Solved]Again: Images & Memory -> Crash after 70 images?!

KMatle

Expert
Licensed User
I am downloading 85 images from my website (640x480, 16 KB). For each image I create a new Imageview with the downloaded image and add it to a scrollview. Actually nothing special, but the app has memory problems after about only 70 images (even if these are much bigger in an imageview but 70 * 2 MB would be 140 MB)...

Any ideas? (or am I dumb?)



Log:

B4X:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
JobName = GetFileList, Success = true
4942
JobName = GetImage, Success = true
15796
Anzahl: 1
JobName = GetImage, Success = true
15823
Anzahl: 2
JobName = GetImage, Success = true
15767
Anzahl: 3
JobName = GetImage, Success = true
15805
Anzahl: 4
JobName = GetImage, Success = true
15839
Anzahl: 5
JobName = GetImage, Success = true
16036
Anzahl: 6
JobName = GetImage, Success = true
15784
Anzahl: 7
JobName = GetImage, Success = true
15789
Anzahl: 8
JobName = GetImage, Success = true
15754
Anzahl: 9
JobName = GetImage, Success = true
15764
Anzahl: 10
JobName = GetImage, Success = true
15794
Anzahl: 11
JobName = GetImage, Success = true
15730
Anzahl: 12
JobName = GetImage, Success = true
15781
Anzahl: 13
JobName = GetImage, Success = true
15731
Anzahl: 14
JobName = GetImage, Success = true
15728
Anzahl: 15
JobName = GetImage, Success = true
15730
Anzahl: 16
JobName = GetImage, Success = true
15799
Anzahl: 17
JobName = GetImage, Success = true
15790
Anzahl: 18
JobName = GetImage, Success = true
15782
Anzahl: 19
JobName = GetImage, Success = true
15765
Anzahl: 20
JobName = GetImage, Success = true
15820
Anzahl: 21
JobName = GetImage, Success = true
15767
Anzahl: 22
JobName = GetImage, Success = true
15826
Anzahl: 23
JobName = GetImage, Success = true
16049
Anzahl: 24
JobName = GetImage, Success = true
15751
Anzahl: 25
JobName = GetImage, Success = true
15782
Anzahl: 26
JobName = GetImage, Success = true
15764
Anzahl: 27
JobName = GetImage, Success = true
15795
Anzahl: 28
JobName = GetImage, Success = true
15732
Anzahl: 29
JobName = GetImage, Success = true
15771
Anzahl: 30
JobName = GetImage, Success = true
15728
Anzahl: 31
JobName = GetImage, Success = true
15728
Anzahl: 32
JobName = GetImage, Success = true
15698
Anzahl: 33
JobName = GetImage, Success = true
15760
Anzahl: 34
JobName = GetImage, Success = true
15804
Anzahl: 35
JobName = GetImage, Success = true
15685
Anzahl: 36
JobName = GetImage, Success = true
15720
Anzahl: 37
JobName = GetImage, Success = true
15710
Anzahl: 38
JobName = GetImage, Success = true
15735
Anzahl: 39
JobName = GetImage, Success = true
15698
Anzahl: 40
JobName = GetImage, Success = true
15660
Anzahl: 41
JobName = GetImage, Success = true
16077
Anzahl: 42
JobName = GetImage, Success = true
16015
Anzahl: 43
JobName = GetImage, Success = true
16180
Anzahl: 44
JobName = GetImage, Success = true
15816
Anzahl: 45
JobName = GetImage, Success = true
16077
Anzahl: 46
JobName = GetImage, Success = true
15673
Anzahl: 47
JobName = GetImage, Success = true
15737
Anzahl: 48
JobName = GetImage, Success = true
15728
Anzahl: 49
JobName = GetImage, Success = true
15715
Anzahl: 50
JobName = GetImage, Success = true
15791
Anzahl: 51
JobName = GetImage, Success = true
16000
Anzahl: 52
JobName = GetImage, Success = true
16063
Anzahl: 53
JobName = GetImage, Success = true
16154
Anzahl: 54
JobName = GetImage, Success = true
16124
Anzahl: 55
JobName = GetImage, Success = true
15710
Anzahl: 56
JobName = GetImage, Success = true
16100
Anzahl: 57
JobName = GetImage, Success = true
15747
Anzahl: 58
JobName = GetImage, Success = true
16031
Anzahl: 59
JobName = GetImage, Success = true
15646
Anzahl: 60
JobName = GetImage, Success = true
16101
Anzahl: 61
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
16071
Anzahl: 62
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
16063
Anzahl: 63
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
15995
Anzahl: 64
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
15996
Anzahl: 65
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
16046
Anzahl: 66
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
JobName = GetImage, Success = true
16028
Anzahl: 67
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
JobName = GetImage, Success = true
16104
Anzahl: 68
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
JobName = GetImage, Success = true
15962
Anzahl: 69
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
JobName = GetImage, Success = true
15763
Anzahl: 70
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
JobName = GetImage, Success = true
16095
Anzahl: 71
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
JobName = GetImage, Success = true
15777
Anzahl: 72
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
JobName = GetImage, Success = true
Error occurred on line: 82 (main)
java.lang.NullPointerException
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:630)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA$3.run(BA.java:320)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
An error occurred:
(Line: 84) Select Job.JobName
java.lang.NullPointerException
Code:
B4X:
      Case "GetImage"
             anzDownl=anzDownl+1
            Log("Anzahl: " & anzDownl)
            btn.Text="Downloading..." &anzJobs&"/"&anzDownl
            If anzJobs=anzDownl Then
               btn.Text="Download complete..."
            End If
                       
            Dim im As ImageView
            im.Initialize("")
            im.Bitmap=Job.GetBitmap
            sv.Panel.AddView(im,5%x,y,90%x,50%y)
            y=y+im.Height+2dip
            sv.Panel.Height=y
                       
            Dim la As Label
            la.Initialize("")
            la.TextColor=Colors.white
            la.Text=Job.Tag
            sv.Panel.AddView(la,5%x,y,90%x,20dip)
            y=y+la.Height+2dip
            sv.Panel.Height=y
 

KMatle

Expert
Licensed User
I knew the problem from the forum but I never thought that about 70 small images could cause this. My solution is to copy all images to a folder (the filenames to a list) and then load them on demand.

Funny that we are able to create huge libgdx 3d superduper games but are not able (at least me) to load some images at once :mad:
 

RandomCoder

Well-Known Member
Licensed User
In my UPNP Browser app I followed someone's advice and utilised bump scrolling in a CustomListView. I only show a small subset of the results at any one time. When the user scrolls to the end I reinitialise the contents with the next set of results (or previous set if scrolling back) and allow the user to continue scrolling. It works reasonably well. But I would have preferred an event to trigger when reaching the end of the list as that was a little tricky bit to get right.
 
Top