B4J Question Increase the Java Heap Space size

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I had another issue which I think is caused to the Java Heap Space size and causing it to ran out of memory.

I am trying to work out how to increase the Java Heap Space size, and got a few questions about it..

I have come across the thread: https://www.b4x.com/android/forum/threads/parsing-huge-text-files.34923/

If I use:
B4X:
#VirtualMachineArgs: -Xms1024m -Xmx1024m

I am guessing that will set the java heap space to 1024MB (1GB) ?

If I use:
B4X:
#VirtualMachineArgs: -Xms2048m -Xmx2048m
Would that increase it to 2048MB (2GB) ?

Or am I looking at this wrong ?

After saying this, I also noticed Erel wrote the following in the other thread (from the link above):
Note that #VirtualMachineArgs attribute only affects the program when you run it from the IDE.

Does this mean it doesn't effect the release version of my B4J app, and only effects it while debugging in the IDE? (If that is the case is there a way in doing this in release mode?)
 

udg

Expert
Licensed User
Longtime User
When you launch your B4J app you use something like:
B4X:
/usr/bin/java -Xmx256m -jar /opt/udgapps/varius/varsvc1.jar

If we want to assign minimum 2 GB and maximum 5 GB to JVM, we need to write:

-Xms2G -Xmx5G
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
If we want to assign minimum 2 GB and maximum 5 GB to JVM, we need to write:

-Xms2G -Xmx5G

So if I run my B4J as service on Linux, I could use something like:
B4X:
[Unit]
Description=CloudServer Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/java -Xms1024m -Xmx2048m -jar /opt/CloudServer/CloudServer.jar
StandardOutput=syslog
StandardError=syslog

SuccessExitStatus=143
Restart=on-abort

[Install]
WantedBy=multi-user.target

Based on the above it would use min 1024 (1GB) and a max of 2048m (2GB).

Would I be correct in doing the above ?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
It's more or less what I have in my service, so I guess it will work for you too.
 
Upvote 0
Top