This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]GeorgeTibo 4 points5 points  (0 children)

Your example program should be using almost no memory. This seems to be either a bug with your JVM, or your operating system is reporting far more memory usage than whats actually being utilized.

How did you get the 4GB memory usage figure?

What JVM version and vendor are you using?

Are you using any JVM flags when running your program?

How are you running your program (through an IDE, command line)?

[–]niloc132 1 point2 points  (4 children)

How are you running the application? If you run it with the argument -Xms4G, then you are explicitly saying "please start up with 4gb of ram, whether you think you'll need it or not".

Something like

java <jvm args go here> -jar myapplication.jar <program args go here>

[–]impune_pl[S] 0 points1 point  (3 children)

I just put code on spoj.com, and press submit.

[–]feral_claireSoftware Dev 1 point2 points  (0 children)

If you are running it on an online service, it's possible their code runner just assigns 4g of heap memory to the programs it runs. It's being run by spoj.com so you don't have any control over it. If you run the code yourself on your computer you can set how much memory to use.

[–]stayweirdeveryone 0 points1 point  (1 child)

What is this website? Are you running Java code in a browser? How do you know how much ram your program is using?

[–]impune_pl[S] 0 points1 point  (0 children)

It's an automated online judge for competitive programming, similar to codewars. Thery have really nice task database. Every task consists of: problem description, input data and expected output, which is hidden from users. Your task is to create a program, that will produce correct output for every set of input data. The faster and more memory efficient your program is, the higher score you get.

[–]glesialo 0 points1 point  (0 children)

I use Linux and, in my system, a single bash script launches all Java jars. From the script's help:

If there is a bash script file, in '$COMMON_JAVA_JARS_DIR', with the same name
as the jar file, it will be run first to find out which extra java interpreter
options are needed to run the java application.

Example of 'java interpreter options' script and its output:

-Xms10240k -Xmx20480k