Android Question Downsampling image due to lack of memory.

Douglas Farias

Expert
Licensed User
Longtime User
Hi
what is this error?
i have all time but i m not downloading images

is because i have many querys ? i realy dont know why this
jobs querys ?

LogCat connected to: B4A-Bridge: motorola XT1033-359321054369100
--------- beginning of /dev/log/main
** Activity (main) Pause, UserClosed = false **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=click.fight.vallow/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Resposta do Servidor: [{"NickName":"doidloko","StatConta":"2"}]
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = true **
** Activity (perfil) Resume **
Resposta do Servidor: [{"UserID":"35","StatConta":"2","NickName":"doidloko","SocID":"100000606767838","SocNet":"Facebook","FirstName":"Douglas","LastName":"Eduardo","CompName":"Douglas Eduardo","Gender":"male","DataNasc":"1992-08-03","Email":"[email protected]","Locale":"pt_BR","CamFotoPerfil":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc3\/t1.0-1\/c33.0.200.200\/p200x200\/10325792_758162660880619_4072345100765266674_n.jpg","Country":"Brazil","City":"S\u00e3o Leopoldo","VotesUp":null,"VotesDown":null,"TotalVotes":null,"isVerified":null,"Strikes":null}]
** Activity (perfil) Pause, UserClosed = true **
** Activity (main) Resume **
Resposta do Servidor: [{"NickName":"doidloko","StatConta":"2"}]
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = false **
** Activity (perfil) Resume **
Resposta do Servidor: [{"UserID":"35","StatConta":"2","NickName":"doidloko","SocID":"100000606767838","SocNet":"Facebook","FirstName":"Douglas","LastName":"Eduardo","CompName":"Douglas Eduardo","Gender":"male","DataNasc":"1992-08-03","Email":"[email protected]","Locale":"pt_BR","CamFotoPerfil":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc3\/t1.0-1\/c33.0.200.200\/p200x200\/10325792_758162660880619_4072345100765266674_n.jpg","Country":"Brazil","City":"S\u00e3o Leopoldo","VotesUp":null,"VotesDown":null,"TotalVotes":null,"isVerified":null,"Strikes":null}]
** Activity (perfil) Pause, UserClosed = true **
** Activity (main) Resume **
Resposta do Servidor: [{"NickName":"doidloko","StatConta":"2"}]
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = false **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
** Activity (perfil) Resume **
Resposta do Servidor: [{"UserID":"35","StatConta":"2","NickName":"doidloko","SocID":"100000606767838","SocNet":"Facebook","FirstName":"Douglas","LastName":"Eduardo","CompName":"Douglas Eduardo","Gender":"male","DataNasc":"1992-08-03","Email":"[email protected]","Locale":"pt_BR","CamFotoPerfil":"https:\/\/fbcdn-profile-a.akamaihd.net\/hprofile-ak-frc3\/t1.0-1\/c33.0.200.200\/p200x200\/10325792_758162660880619_4072345100765266674_n.jpg","Country":"Brazil","City":"S\u00e3o Leopoldo","VotesUp":null,"VotesDown":null,"TotalVotes":null,"isVerified":null,"Strikes":null}]
** Activity (perfil) Pause, UserClosed = true **
** Activity (main) Resume **
Resposta do Servidor: [{"NickName":"doidloko","StatConta":"2"}]
** Activity (main) Pause, UserClosed = false **
** Activity (perfil) Create, isFirst = false **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
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.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
 

Attachments

  • Sem título.png
    Sem título.png
    144.5 KB · Views: 363

Erel

B4X founder
Staff member
Licensed User
Longtime User
As Guru Erel said, just add the following to your manifest file:
I'm sure that I didn't say that you just add this attribute and forget about memory issues...

These messages mean that there wasn't enough memory available to load the bitmap so the bitmap was downsampled. Are you using LoadBitmapSample to load the images?
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
I'm sure that I didn't say that you just add this attribute and forget about memory issues...

Everything that works well for me, I always think that it comes from you Erel haha, sorry for that :) :) (kidding)

@ ilan12041981: Hi, please note that the manifest trick does work only for Android version > = 3 (SDK 11) as I understand.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
sdk 11 and above right?

what can i do to free memory ?
i am only loading image to a imageview everytime its been clicked
what would be the best way to do it?

i have 59 imageviews and everytime a imageview is clicked i change his backgorund image

i have decleared the image ("im") in globals


this is my code:

B4X:
Sub img_Click

Try


Dim buchstabe As String 
'Dim hleft As Button
'hleft.Initialize ("hleft")

Dim str As String 


im = Sender
str = im.Tag 

If hexcolor = 1  Then
'hleft = hex1 
buchstabe = "a" '0|10|a"
Else If hexcolor = 2 Then
'hleft = hex2
buchstabe = "b" '0|02|b"
Else If  hexcolor = 5  Then
'hleft = hex3
buchstabe = "c"
Else If hexcolor = 6  Then
'hleft = hex4 
buchstabe = "d"
Else If hexcolor = 3  Then 
'hleft = hex5
buchstabe = "e" 
End If

'Try
'    clickmp2.Play 
'Catch
'    Log("clickmp2.Play")
'End Try



If str.SubString2(0,1) = "0" Then 'nicht besetzt
'    If hleft.Text > 0 Then 
        im.Tag = "1" & str.SubString2(1,4) & buchstabe 'jetzt besetzt
        im.Bitmap = LoadBitmap(File.DirAssets, "hex" & hexcolor & ".png")
        im.Gravity = Gravity.FILL 
'        hleft.Text =  NumberFormat(hleft.Text - 1 ,1,0)
       
       
        'start check
        Dim searchstr As String 
        Dim found As Boolean 
       
        found = False 
        searchstr = ""
       
        For i = 0 To chklist1.Size - 1
        searchstr = chklist1.Get(i) 
            If searchstr = (str.SubString2(2,4) & buchstabe) Then 
                found = True 
                chklist1.RemoveAt(i)
                Exit 
            End If
        Next
       
        If found = False Then 
        chklist1.Add(str.SubString2(2,4) & buchstabe)
        End If
       
        If chklist1.Size = 0 Then 
        gameend
        End If
       

Else

    im.Tag = "0" & str.SubString2(1,4) 'jetzt besetzt
    im.Bitmap = LoadBitmap(File.DirAssets, "dot1.png")
    im.Gravity = Gravity.CENTER 

    If str.Contains("a") Then
'    hex1.Text = NumberFormat(hex1.Text + 1 ,1,0)
    buchstabe = "a"
    Else If  str.Contains("b") Then
'    hex2.Text = NumberFormat(hex2.Text + 1 ,1,0)
    buchstabe = "b"
    Else If str.Contains("c") Then
'    hex3.Text = NumberFormat(hex3.Text + 1 ,1,0)
    buchstabe = "c"
    Else If str.Contains("d") Then 
'    hex4.Text = NumberFormat(hex4.Text + 1 ,1,0)
    buchstabe = "d"
    Else If str.Contains("e") Then
'    hex5.Text = NumberFormat(hex5.Text + 1 ,1,0)
    buchstabe = "e"
    End If
   

        Dim searchstr2 As String 
        Dim found2 As Boolean 
       
        found2 = False 
        searchstr2 = ""
       
        For i = 0 To chklist1.Size -1 
        searchstr2 = chklist1.Get(i) 
            If searchstr2 = (str.SubString2(2,4) & buchstabe) Then 
                found2 = True 
                chklist1.RemoveAt(i)
                Exit 
            End If
        Next
       
        If found2 = False Then 
        chklist1.Add(str.SubString2(2,4) & buchstabe)
        End If
       
        If chklist1.Size = 0 Then 
        gameend
        End If
       
'        codetosend = codetosend.SubString2(0,codetosend.Length - 2)

End If

    Label1.Text = chklist1.Size 

Catch
Log("")
End Try

   
End Sub
 
Upvote 0

strat

Active Member
Licensed User
Longtime User
sdk 11 and above right?

what can i do to free memory ?
i am only loading image to a imageview everytime its been clicked
what would be the best way to do it?

i have 59 imageviews and everytime a imageview is clicked i change his background image

i have decleared the image ("im") in globals


In my opinion you are using too many imageviews for one app. You can make some optimization for more free memory.
Instead of Loadbitmap, you can use Loadbitmapsample. Copying all bitmap samples to one scrollview of a panel, you can show all pictures in one panel( I don't know what you want to do. It's only a suggestion)
I got same error in my latest app, then I used such optimization and error has been solved.
This is my game that I solved memory problem

https://play.google.com/store/apps/details?id=com.eem.marka
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
thanx strat i tried it and no success

i create only 5 imageviews and load the bitmap to them then i just use for every other imageview the same bitmap without loading a new bitmap

like:

im1.bitmap = loadbitmapsample(...,...,54dip,54dip)

then i use imageview1.bitmap = im1.bitmap

no more loadbitmap but still so success

in android 4 i dont have any problems only in sdk 10 and i would like to change the min sdk to the sdk that use the manifest trick bsnqt said

@ ilan12041981: Hi, please note that the manifest trick does work only for Android version > = 3 (SDK 11) as I understand.

after i use this trick i dont have any problems in android 4.1.2 and i dont have a device with sdk11 so i cannot test if sdk11 will do this menifest trick
like he said :(
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
i go need use 100+ imageviews how can i?
all user can upload photos and it return in thumb images to app

all user can send 100 photos it is not possible on b4a ? o_O
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i dont think it has something todo with b4a it's only depending on the device memory, so what we should do is or try better coding or limit the app to sdk11+ and use the manifest trick of bsnqt
 
Upvote 0

CyclopDroid

Well-Known Member
Licensed User
Longtime User
mmmmh my App, in my smarth working but, if I test it into aVirtual Device (7" WSVGA Tablet), Now, give me the error 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.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
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.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory: 4
Downsampling image due to lack of memory: 8
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
Downsampling image due to lack of memory.
Downsampling image due to lack of memory: 2
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.
....
....
....

and the Game Screen is Stopped into avvise (ToastMessageShow command).
First, It working into this Virtual Device, but now the Game have more implementation and grahics object. :(
Into Virtual Device of my Smartphone, i dont hav any problem.
The Immage are into DirAssets and are load with the LoadBitmap command.
I've a big DB (13MB) when transfert of DirAssets into DirInternal, for reading.
I've insert a bsnqt trick into a manifest... but nothing, not work in this device... I hope when the errors is cause to Virtual Device :p
 
Last edited:
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
I have the same memory problem. I have 2 activities with imageviews that are loaded via loadbitmapsample. After number of switches between activities I get "Downsampling image due to lack of memory".
To leave an activities I use Activity.RemoveAllviews and Activity.finish.
At second activity I use the function:

Sub
GetFreeMemory As Long




Dim jo AsJavaObject




Return jo.InitializeStatic("java.lang.Runtime").RunMethodJO("getRuntime", Null).RunMethod("totalMemory", Null)



End Sub
to see the memory usage.
Each time I switch to second activity the memory usage is growing and when it achives the number 62853104(62MB I assume) the "Downsampling image due to lack of memory" appears. It looks like Activity.RemoveAllviews and Activity.finish do not free the memory. What is the problem?
 
Upvote 0

EvgenyB4A

Active Member
Licensed User
Longtime User
Have you tested it in Release mode?
I have tested in release mode and it looks OK. The memory usage grows from 9 MB at start of application and stops on 13 MB. So the problem of memory usage is in debug mode. I hope it is fixed in B4A v4.0.
By the way: The function GetFreeMemory shows indeed the memory usage of the application or shows available free memory as goes from its name?
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I see this error all the time when rapid debugging my main app. It is a remote control app with 50+/- buttons that all use a custom image.

Works fine in release, and even in rapid debug it usually doesn't happen until after I've run the app a few times.

I'm not too concerned about it since it works fine in release but figured I'd mention it here if it would do any good towards some kind of fix. :)
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I don't recall getting a beta invitation but may have missed it. I renewed my Enterprise license on April 24, 2013, so I would have expected an invitation. With that in mind, renewing the enterprise version at the discounted price does reset the two years of updates, correct? I can wait for the final release since it's supposed to be soon.
 
Upvote 0
Top