Reputation: 1939
Java vm arguments can be retrieved at an later point in time by calling:
ManagementFactory.getRuntimeMXBean().getInputArguments()
This call explicitly excludes the main args
Returns the input arguments passed to the Java virtual machine which does not include the arguments to the main method
Is it safe to assume that supplying an argument via the command line is wiped from memory once the main method exists, or can we clean up safely afterwards ourselves? (In this particular example I want the user to supply an encryption/decryption key) which should stay in memory as short as possible.
Upvotes: 0
Views: 75
Reputation: 98284
Is it safe to assume that supplying an argument via the command line is wiped from memory once the main method exists
Definitely NOT.
Command line is an attribute of OS process. No matter what JVM or what application you start, the original command line is kept by the OS as long as the process lives. E.g. on Linux it is accessible through /proc/PID/cmdline
.
Upvotes: 1