Matlab javabuilder and memory issues

I am having some problems with my matlab code compiled by javabuilder. My application is mostly split like this:

  • GUI: Java
  • Calculations: Matlab

The main problem is that when I compile my matlab code with javabuilder in Matlab (R17, 2007a), I have less available memory than when I compile the same code into an exe file. I have confirmed this with a function function (memstats). My arrays are usually in size orders of 1,000,000 x 25, and this is not initialized when run from java as the largest contiguous memory space is too small (the largest is around 65MB, not around 1200MB when run as an ML exe) ... My installation is running Windows XP Professional x86 and has 4GB of memory.

I have tried these two matlab / c compilers (configured with mbuild -setup command on matlab command line):

  • Lcc-win32 C 2.4.1
  • Microsoft Visual C ++ 6.0 (also with the / LARGEADDRESSAWARE flag, which doesn't seem to help)

Any suggestions?

+1


source to share


3 answers


Actually you might need to shrink the Java heap. The memory in your process, at least in regular Matlab, is shared between Matlab and Java. If you increase the Java heap size, you will decrease the available memory for Matlab arrays accordingly. Matlab matrices live in regular C-style memory, not Java GCed memory.

I am guessing what is happening is that your Java application loading the built-in javabuilder library is configured to have a larger Java heap than Matlab IDE. Matlab starts off with a little Java heap. Here's how to display it from inside Matlab.

function show_javamemory()

rt = java.lang.Runtime.getRuntime();
M = 2^20;
disp(sprintf('Java heap: %d M total, %d M max, %d M free',...
    round(rt.totalMemory()/M), round(rt.maxMemory()/M), round(rt.freeMemory()/M)));

      

In my R2009a, I can see this.



>> show_javamemory()
Java heap: 62 M total, 125 M max, 28 M free

      

This java.opts file in% matlabroot% / bin / win32 controls the JVM embedded in Matlab when it is started as an IDE. I don't think it will affect the apps loaded into your javabuilder built library. They need to be adjusted by passing parameters to whatever java command line invoking them.

Try running show_javamemory () from your compiled application to see how its heap is configured like (and if your java.opts change has changed), then changing the Java options to shrink the heap.

+1


source


I think the solution to your problem is to increase the Java VM heap space as described here:



How do I increase the heap space for the Java Virtual Machine in MATLAB 6.0 (R12) and later?

0


source


Sorry, I can't leave comments (50 reputation needed) (and it's too long for a comment anyway). I don't think it changed anything. What I did was create "java.opts" in% matlabroot% \ bin \ win32 and set the content to "-Xmx1024m". Then I tried to recompile my application.

This function ("memstats") says at the start of my matlab function:

Physical Memory (RAM):
    In Use:                             1568 MB (62059000)
    Free:                               2013 MB (7ddb2000)
    Total:                              3582 MB (dfe0b000)
Page File (Swap space):
    In Use:                             1608 MB (648ac000)
    Free:                               3872 MB (f20b1000)
    Total:                              5481 MB (15695d000)
Virtual Memory (Address Space):
    In Use:                             1611 MB (64b4c000)
    Free:                               1460 MB (5b494000)
    Total:                              3071 MB (bffe0000)
Largest Contiguous Free Blocks:
     1. [at 69b78000]                     53 MB ( 3538000)
     2. [at  ccbf000]                     51 MB ( 3341000)
     3. [at 6eee0000]                     40 MB ( 2820000)
     4. [at 5d36e000]                     28 MB ( 1cd2000)
     5. [at 67d15000]                     23 MB ( 17eb000)
     6. [at 5f211000]                     19 MB ( 13bf000)
     7. [at 6dac0000]                     19 MB ( 13a0000)
     8. [at 71ce7000]                     19 MB ( 1319000)
     9. [at 7a038000]                     18 MB ( 12f8000)
    10. [at 7d1d7000]                     18 MB ( 1239000)
                                        ======= ==========
                                         292 MB (124ff000)

      

0


source







All Articles