OutOfMemoryError when launching application on simulator with large Java heap size

Hi,
I’m faced OutOfMemoryError from my Java application running on my VEE Port simulator even if I increased the Java Heap size a lot (with core.memory.javaheap.size=30000000). Here is the Java source code I use:

	public static void main(String[] args) {
		List<String[]> list = new ArrayList<>();
		long freeMemory = -1;
		for (int i = 0; i < 1_000; i++) {
			freeMemory = Runtime.getRuntime().freeMemory();
			String[] newArray;
			try {
				newArray = new String[5_000];
			} catch (OutOfMemoryError oome) {
				System.out.println(i);
				System.out.println(freeMemory);
				break;
			}
			list.add(newArray);
		}
	}

Here is the output I get:

=============== [ Initialization Stage ] ===============
=============== [ Converting fonts ] ===============
=============== [ Converting images ] ===============
=============== [ Launching on Simulator ] ===============
203
25934732
=============== [ Completed Successfully ] ===============

SUCCESS

We can see here that OutOfMemoryError occurred even if 25934732 bytes of free memory remains in the Java Heap.

Can you help me please ?

Regards,

Jean

Hi Jean,

Your issue relates to a wrong Simulator memory calibration. You can find documentation here: Application Options — MicroEJ Documentation

The Java Heap size you set via core.memory.javaheap.size (30000000 bytes) is greater than the Simulator default Objects Heap size (4096KB / c.f: Application Options — MicroEJ Documentation). Your application will allocate until the limit of 4096KB of the Simulator Objects Heap is reached and then throw a OutOfMemoryError (FYI your application source code allocate ~20MB)

To get your application working, please use the following Simulator options:

Note: option values can be calibrated more accurately according to the Java application you launched.

Regards,

Gaëtan for MicroEJ