B4J Question How to increase Heap size memory (Raspberry)

CR95

Active Member
Licensed User
I try to load large sized images (around 3 M.o) on a PI 3B with 1 G.o memory.

Sometimes, I got the error "Out of memory heap size".

I found that it is possible to increase the Java heap size by using #VirtualMachineArgs attribute :
#VirtualMachineArgs: -Xms600m -Xmx600m

I made several trials with different sizes but I always got this error after compilation :
Invalid initial heap size: -Xms600m -Xmx600m
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Please could you help,
 

Swissmade

Well-Known Member
Licensed User
Longtime User
You can not set this that high with 1GB of memory on your PI I think.
 
Upvote 0

CR95

Active Member
Licensed User
Thanks but NO
I made a trial with 100 M.o and I got the same error
I found that 600 M.o is the Heap size recommended value for 1 G.o total memory by Oracle
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
Maybe even don't use this parameters and let java decide.
But I think that your images maybe be to much but without code we can not see if it is so.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I suppose you could try
B4X:
#VirtualMachineArgs: -Xms300m -Xmx600m

(Start with 300 meg and allowed to grow to 600 meg)
 
Upvote 0

CR95

Active Member
Licensed User
Maybe even don't use this parameters and let java decide.
If I let java decide, I get "java.lang.OutOfMemoryError: Java heap space" message
I think that your images maybe be to much but without code we can not see if it is so.
Code is simple :
B4X:
        Dim bg As B4XBitmap = xui.LoadBitmapResize(Rep, FileName, 1920dip, 1080dip, True)
               B4XImageView1.SetBitmap(bg)
I have the feeling that my issue is coming from the "speed" of loading the images. My program is a sort of "diaporama" which shows one image every second.
And I guess that some large images are not completly loaded when the program starts to load the following image !
But I did not find a way to know when image loading is 100% finished. Any idea ?

@Daestrum
I don't think the error is coming from the value (I tested different sizes and yours).
 
Upvote 0
Top