Set memory from command line upon startup (headless)

Hi All,

Does someone know how to set the java memory limit when running ImageJ from the command line?

Hi @Christian_Tischer,

did you see this wiki page:

It seems to be a bit out-of-date (the launcher is now ImageJ-<platform>, not simply fiji any more), but you should still be able to pass java flags, in particular:

-Xms4000m -Xmx4000m

If you find that this works for you, it would be great if you could update that wiki page and/or add an entry to the Frequently Asked Questions about it.


Thanks a lot!
We will test it!

I tried it like this:

/Applications/ -Xms4000m -Xmx4000m --headless --run Hello "name='Tischi'"

And got this response:

[WARNING] Ignoring invalid argument: -Xms4000m
[WARNING] Ignoring invalid argument: -Xmx4000m

If one takes a look at the command line help:

/Applications/ --help

One finds:

--heap, --mem, --memory <amount>
	set Java's heap size to <amount> (e.g. 512M)

This works for me like this…

/Applications/ --mem=3000M

…in a sense that inside Fiji [Edit > Options > Memory & Threads] shows (roughly) the corresponding number.

What I don’t know is whether this is sufficient or whether the -Xmx would do something different/additional?

1 Like

One rather simple way at least for linux would be to add the -Xmx dynamically to the ImageJ.cfg located in the Fiji root folder. When launching Fiji, these values are taken and appear in ‘Edit->Options->Memory…’

1 Like

But be aware that running this on a compute cluster, you would need one Fiji installation per job array where you can specifically modify the ImageJ.cfg file. In other words this approach would not work in a scenario where one has one central Fiji installation for the cluster.

I know. That’s why I first generate a backup of the cfg file and then write my parameters in it and start Fiji. After that, I copy the backup back.

I would in fact consider to

  1. copy the whole Fiji to another folder specific to that job array.
  2. modify the config file only in this Fiji

like this other potential job arrays can always rely on the one “master” Fiji being in place in an unmodified state.