Can I increase Java Heap Memory by decreasing the tools when I install the Matlab program OR adding more Memory to my laptop, please? Thank you.
MATLAB: How to increase Java Heap Memory
Related Solutions
There is no optimal value for Java heap space, as the best allocation depends on what you are doing. The default heap size is sufficient in most cases.
Although, creating a larger Java heap gives more space to some types of objects (especially graphics objects or Simulink), it reduces the amount of memory available on your system for other tasks (like most MATLAB computations, and storing variables). If you are using a lot of Simulink and not performing very many calculations, then you will benefit from more Java heap space. If you are executing numerically intensive scripts with lots of large variables and do little or no plotting, then you may benefit from less Java heap space.
To add to what Daniel has already written, consider these lines:
function obj=lu_apply(A) [L,U]=lu(A); obj.f=@(X) U\(L\X); end
The L and U matrices get created inside the function lu_apply. They are local to the function and will get destroyed once the function returns. The following line:
obj.f=@(X) U\(L\X);
creates a function handle using the local L and U variables as part of the function definition. At that time, shared data copies of L and U are created and become embedded in the data area of the function handle ... i.e., they essentially become part of the function handle variable itself. Basically these shared data copies of L and U become snapshots of the current state of L and U at the time of the function handle creation and will remain as constants as far as the function handle is concerned.
Whatever happens to L and U downstream doesn't affect this function handle anymore. In particular, when the function returns, the local variables L and U are destroyed, but the shared data copies of them that were created earlier still live on (and use memory) as part of the function handle. The only way to clear this memory is to clear the function handle itself. I don't know of any way to directly interrogate a function handle to determine the sizes of the embedded variables it contains, since I am not familiar with how function handle definitions are encoded in the data area of the variable.
Best Answer