Measuring the Java Heap Space Memory
Software components that are based on Java®, such as certain parts of COMSOL Multiphysics, are predefined to use only a limited amount of memory. This limit, the Java® heap space, is specified during startup. Note that the Java® heap space only affects certain parts of the software and not, for example, meshing or solvers. By default, COMSOL Multiphysics allocates 2 GB of Java® heap space memory. See the Reference Manual for information about increasing the available heap space memory.
In a method, you can measure the amount of heap space memory currently in use. For example, while debugging, you can add the following code:
Runtime runtime = java.lang.Runtime.getRuntime();
runtime.gc();
debugLog("Used memory (MB): "+(runtime.totalMemory()-runtime.freeMemory())/(1024*1024));
The first line adds a request to run the Java® garbage collector.
In order to monitor the memory usage in an application, you can replace debugLog with message.