Comments on: Controlling the Java Heap Size https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/?s_tid=feedtopost News from the intersection of MATLAB, Community, and the web. Tue, 03 Apr 2012 13:56:15 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: Michael Katz https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-8719 Tue, 03 Apr 2012 13:56:15 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-8719 @Christopher,

Yes that is how it’s supposed to be done. It’s a bit of advanced maneuver, which is why we don’t make it easy. I’ll let the team know about upping the slider limit.

]]>
By: Christopher Barber https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-8707 Thu, 29 Mar 2012 19:49:56 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-8707 My issue with my java.opts file was that it needs to be in the starting current directory when matlab is started, which is not necessarily the same as the bin/ directory on Windows. I tweaked my startup shortcut to explicitly specify a starting directory.

]]>
By: Christopher Barber https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-8693 Mon, 26 Mar 2012 21:49:06 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-8693 I am running R2012a on 64-bit Windows 7 and it appears to be ignoring my java.opts file. The only way I have found to increase the max size beyond the 1024MB limit of the preferences dialog is to hack the matlab.prf file directly.

]]>
By: Amro https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-7156 Fri, 02 Jul 2010 22:22:02 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-7156 I’m not specifically making java calls but I am creating fi objects within my mex files (or collecting fimath info from inputs).

I’ll definetly try the clear java option and check technical support if this persists further.

Thanks for your help.

]]>
By: Mike https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-7146 Fri, 25 Jun 2010 12:03:34 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-7146 Are your MEX functions making java calls? If so, they may not be garbage collected if you’re dangling pointers. In MATLAB you can leak Java objects by attaching them to handles and then not clearing them properly, I forget the exact sequence, it’s been awhile since I’ve had to deal with that. You can also try “clear java” in that case. If that doesn’t work, technical support might be able to help you.

]]>
By: Amro https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-7144 Thu, 24 Jun 2010 22:17:36 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-7144 Thanks mike for the informative post!

I have a program which runs many fixed point MEX functions, after running the code around 10K times I’d get the java heap space error. Although increasing heap space may help, I feel it just makes the simulation run for another 10K runs before running out again.

It seems that java is somehow accumulating memory usage and not clearing variables with each new call to my functions. Would you be able to guide me in the right direction?

]]>
By: Yair Altman https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-7092 Wed, 09 Jun 2010 11:02:46 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-7092 Followup on the Java object size issue: please take a look at Classmexer (http://www.javamex.com/classmexer/). It uses JVM instrumentation (available on JVM 1.5+) to report object sizes. Notwithstanding all the correct reservations you have raised above, I believe that JVM’s own instrumentation gives the closest possible estimate of the actual object size.

I am using classmexer successfully in Matlab, after simply adding classmexer.jar to the classpath and the relevant -javaagent switch to my java.opts.

While deep-scanning takes some time to execute and cannot therefore be placed in the Workspace table’s Cell-renderer, a simple asynchronous thread that would periodically deep-scan Java objects and refresh the table should be relatively easy to implement.

]]>
By: Yair Altman https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-6992 Wed, 28 Apr 2010 15:02:18 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-6992 Thanks Mike. You are of course correct with all your points. It is simply frustrating for me not to be able to profile Java memory usage as easily as Matlab memory or CPU usage.

My most relevant use-case is trying to debug a GUI-laden application that keeps running into the Java heap memory barrier. It also happens when I use external Java classes that map large data sets. There can be many different causes: memory leaks, unnecessary leftover objects, too many concurrently-active components, inefficient memory hibernation etc.

It is very difficult to debug such issues in today’s Matlab. I usually depend on gut feeling, trial-and-error, or (when all else fails) JDK tools. This takes much more time and is less effective to debug than for Matlab code.

I’m not asking for a full-blown heap-walker – a simple reliable report of object sizes will be most appreciated. And yes, I do appreciate that my request is anything but simple – not because of Matlab, but because of Java design limitations (now that James Gosling left Sun, maybe you can hire him… just kiddin’…).

Thanks,
-Yair

]]>
By: Mike https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-6991 Tue, 27 Apr 2010 13:17:16 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-6991 @Yair,

It’s not just a matter of evaluating the free memory before and after, because each java command from MATLAB is not an atomic evaluation. There are objects created for the typing events, callbacks thrown, and JMI events that happen as well. Also garbage collection could be run between two evaluations of the free memory, making it seem like a new object had negative size! :) If you have a use case for knowing the size of a Java object, I’d be happy to pass that along to our infrastructure team.

@Ted,
Let us know if you have topics you’d like to see.

@Jonas,
I believe The java.opts file in your startup directory will take precedence over the settings, but I am double checking. We limit the size of the slider to prevent people from allocating too much memory and hosing their system. You can always specify a higher value with -Xmx in a java.opts file.

]]>
By: Jonas https://blogs.mathworks.com/community/2010/04/26/controlling-the-java-heap-size/#comment-6990 Mon, 26 Apr 2010 18:12:15 +0000 https://blogs.mathworks.com/desktop/2010/04/26/controlling-the-java-heap-size/#comment-6990 Nice feature. I have a few questions, though:
– If both set the heap size and add a java.opts file, which one is being considered?
– In my Matlab installation, the java heap size is limited to 256 MB of RAM in the GUI. Why? I’d like to be able to set it to 1GB to handle large numbers of java objects and use (most of) the other 7GB of RAM to store Matlab variables.

]]>