Android Question Recycle unused BMP

AlpVir

Well-Known Member
Licensed User
Longtime User
The following lines :
B4X:
Dim Obj1 As Reflector
Obj1.Target = BMP
Obj1.RunMethod ("recycle")
should free the memory bitmap BMP, no longer desired.
However, by testing the amount of memory before and after get the same value.
B4X:
Sub GetFreeMemory As Long
    Dim jo As JavaObject
    Return jo.InitializeStatic("java.lang.Runtime").RunMethodJO("getRuntime", Null).RunMethod("totalMemory", Null)
End Sub
What explanation can you give ?
Thank you for your attention
 

udg

Expert
Licensed User
Longtime User
Hi,
it is my understanding that "recycle()" doesn't immediately frees memory; it just marks it as available.
Read here for more.

udg
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Thanks for the clarification.
I have serious problems in the management of RAM.
After some use appears the error :
java.lang.OutOfMemoryError: bitmap size Exceeds VM budget
The offending statement is as follows
B4X:
bmp.InitializeMutable (7200,600)
and then I would keep an eye on the consumption of RAM.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Erel, I'm confused. I thought I had read somewhere that after using BMP was a good idea to launch a "recycle".
In any case I still evere messages "out of memory".
I condensed my problem in the small attached project whose code is this:
B4X:
Sub Globals
    Dim Bot7200      As Button
    Dim Bot14400     As Button
    Dim Bot28800     As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Bot7200.Initialize ("Bot7200")
    Activity.AddView (Bot7200,10dip,10dip,150dip,35dip)
    Bot7200.Text ="7200x600 pixel"
   
    Bot14400.Initialize ("Bot14400")
    Activity.AddView (Bot14400,10dip,50dip,150dip,35dip)
    Bot14400.Text ="14400x600 pixel"
   
    Bot28800.Initialize ("Bot28800")
    Activity.AddView (Bot28800,10dip,90dip,150dip,35dip)
    Bot28800.Text ="28800x600 pixel"
End Sub
Sub Bot7200_click
    CreaBMP (7200)
End Sub
Sub Bot14400_click
    CreaBMP (14400)
End Sub
Sub Bot28800_click
    CreaBMP (28800)
End Sub
Sub CreaBMP (larg As Int)
    Dim bmp   As Bitmap
    Dim C         As Canvas
    Dim brect     As Rect
    Dim Orizzonte As Float = 0.5
    Dim out       As OutputStream
   
    bmp.InitializeMutable (larg,600)
    C.Initialize2 (bmp)
    brect.Initialize (0,0,DipToCurrent(larg), DipToCurrent(600))  
    C.DrawRect (brect, Colors.white, True, DipToCurrent(600)) 
    '--- draw
    For px = 0 To larg Step 200
        C.DrawLine (px,600*Orizzonte-10,px,600*Orizzonte+10,Colors.LightGray,1dip)
    Next
    '--- orizzonte
    C.DrawLine (0,600*Orizzonte,larg,600*Orizzonte,Colors.Black,1dip)  
    C.DrawText ("Test " & larg,0,580,Typeface.default,16,Colors.Blue,"LEFT")
    '--- write
    out = File.OpenOutput(File.DirRootExternal, "test.jpg", False)
    bmp.WriteToStream (out,80,"JPEG")
    out.Close
    Msgbox ("Test","OK")
End Sub

I can only create the image 7200x600 pixels. The other not.
Thanks in advance
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Using Android 2.3.3 and then SetApplicationAttribute (android: largeHeap, "true") can not be used.
So are virtually IMPOSSIBLE to draw some simple line on a bitmap 14400x600 pixels ?
A different approach would be feasible ?
For example, load a picture 14400x600 (only 36 KB !) completely empty and draw on.
Or draw on a bitmap of 7200x600 pixels and then on a second bitmap of 7200x600 (this can be done) and then combine (how?) the two JPG files in one 14400x600 ?
Thanks in advance.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
What about my two alternative hypotheses (or other) ....
A different approach would be feasible ?
For example, load a picture 14400x600 (only 36 KB !) completely empty and draw on.
Or draw on a bitmap of 7200x600 pixels and then on a second bitmap of 7200x600 (this can be done) and then combine (how?) the two JPG files in one 14400x600 ?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you mean like panoramic views (flat or 360°) ?

you could split it up in sections and only load the ones that are (near) visual.

on the other hand...

you don't need that large bitmap, just copy the portion that you need
to a bitmap that has the size of the screen or even less and scale up to screensize.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
My views are all 360 degrees with cylindrical projection ("flat"). They also have a mechanism for the recognition of the peaks.
The names of the peaks and their coordinates are stored in the EXIF data of JPEG files.

Now I'm adding new features: the "synthetic" views !
For that I would need a picture absolutely empty, white, of 14400x600 pixels (14400=360*40)
On this picture I want to draw some simple line and then record everything in a JPG file.

But it seems that all that exceed the capabilities of a smartphone in memory and have to find an alternative solution.
Later viewing of the JPG file is no problem even if it were to 15000x600 pixels. Already the case with the "photografic" views.
 
Upvote 0
Top