MATLAB Answers

Richard
2

After Allocating a Large Variable and Crashing, MATLAB is Forever Slow

Asked by Richard
on 30 Dec 2013
Latest activity Answered by Yaroslav on 20 Aug 2017
I was playing around with variable allocation sizes to see how it effected my RAM allocation. Another words, looking at a third party memory stats program I would allocate a vector with 1 billion entries and see how much RAM that required.
When I got to allocating 4 billion entries, my entire computer froze. I didn't have a problem with this, I was expecting it to happen at some point. After restarting however, MATLAB seems to be permanently broken. It gets stuck in the busy state upon startup for at least a minute every time. When I try to save a new script, I get weird behavior like the file never being saved even though MATLAB makes me believe it has been. I have tried deleting the AppData\Roaming\Mathwords\R2012b folder but it has no effect. Are there other folders or files like this that I can try removing?
I would like to know the cause of this, but above all I would like to know how to fix this. There must be a way to get MATLAB fixed without having to re-install. Can anyone help?

  5 Comments

Is MATLAB speedier if you start it without the desktop?
From the system command prompt:
matlab -nodesktop
If I type matlab -nodesktop a white window with some lines of text like "To get started type one of these: helpwin, helpdesk or demo" pops up but is unresponsive.
If I type matlab alone with no flag, a matlab gui will open with the same problems I'm experiencing.
It seems that anytime MATLAB needs to create a variable, it stalls out for a minute of so. For example, just typing 2+2 in the command window takes about 15 seconds (because its populating the ans variable I assume). Running any script takes about 30 seconds for it to start.
What is related to memory allocation that I broke when I crashed MATLAB?
Update: The matlab -nodesktop window will eventually become responsive, but it takes over a minute. It has the same problems as the normal GUI versions of MATLAB.
Same problem here...
I was set maxheap in the RunWeka.ini for Weka become 4000m. It is because of my Weka is always OutOfMemory for Machine Learning's training. Then the Weka run normaly without OutOfMemory message.
But after it, my Matlab become very slowly and the accuracy of training data if very decrease... It is weird...
Please help....

Sign in to comment.

6 Answers

Answer by Yair Altman on 1 Jan 2014
Edited by Yair Altman on 1 Jan 2014

Several possibilities spring to mind:
  1. Your antivirus is running wild ( link1, link2, link3 )
  2. You are using a CVS (code-versioning system) that is ill-configured
  3. You use a remote Matlab license server that is unreachable, or you experience license manager lockouts for some reason, or you're using a mis-configured license file or LM_LICENSE_FILE environment variable
  4. You have clashes with other software that uses the same FLEXnet license manager as Matlab ( link1, link2 )
  5. You have mapped drives that are disconnected for some reason but Matlab doesn't know this
  6. You have a very long Matlab path
  7. You have defined a function somewhere on the Matlab path that has a name which overrides some internal Matlab function
  8. Your Matlab installation is critically fragmented on disk (=> run a defragmetation utility)
  9. You are using a toolbox that is ill-configured (e.g., symbolic toolbox)
  10. You are running Matlab via an X-server or SSH
  11. You have disabled toolbox caching in the global Matlab preferences
  12. You have defined numerous workspace variables
  13. You have numerous files loaded in the Editor
  14. You have multiple open figure windows
  15. You are using SELinux without setting the allow_execheap flag (so JIT is disabled)
  16. You are using a vast number of Windows fonts
  17. You are using unnecessary web-proxy auto-discovery
  18. You have insufficient physical RAM to run Matlab, thereby causing extensive disk thrashing
To isolate things, start Matlab with no startup.m file and with only the default MathWorks path (i.e., remove your folders from the path). If it's now ok, then start adding user paths until you find the culprit. If it's not ok, try reinstalling Matlab from scratch.

  1 Comment

Sign in to comment.


Answer by Walter Roberson
on 31 Dec 2013

I would start by deleting matlab.prf out of prefdir . See http://www.mathworks.com/help/matlab/matlab_env/preferences.html#bsoa5yg-1 before starting MATLAB. Then start it, and when you get a prompt, command
rehash toolboxreset; rehash toolboxcache
Another thing I would check would be whether the slowdown is in a network connection at MATLAB startup time. That might be for license checking purposes; there is also something unknown that can require a network connection at startup time in some versions (some kind of authentication ?).
If you are having network problems, one thing to try is to open up your firewall for a moment and see if MATLAB starts faster (remember to close it afterwards.) But oddly the other network issue is most easily diagnosed by turning your network off before starting MATLAB and seeing if it starts quickly. I do not recall what the cause of that second kind of problem was, but I seem to recall that adding an entry for
localhost 127.0.0.1
to your hosts file can help; see http://www.mathworks.com/matlabcentral/newsreader/view_thread/88539 for a mention of where the hosts file lives in MS Windows

  2 Comments

I will try deleting matlab.prf.
I'm fairly certain this has nothing to do with the network. I'm at work and I've never had a network issue before. I use a standalone license. Before this crash I never had this issue. I have no control over the firewall settings. This busy period happens anytime a variable is created, not just upon startup. That is another symptom that makes me sure it's not network related.
The matlab.prf folder is located in the AppData/Roaming/MathWorks/MATLAB/R2012b folder I mentioned I already tried renaming so that MATLAB would create a new fresh folder. This had no effect on the issue I'm describing. The MATLAB preferences are not the problem. Thanks though.

Sign in to comment.


Answer by Yaroslav on 20 Aug 2017

I have had the same problem in my R2017a (!) version. I have been inspecting the memory usage and running time of some function, which creates a large array based on an input size parameter. Alas, for a very large size – instead of throwing out-of-memory error – my computer stuck, so I had to forcefully abort and exit Matlab. Moreover, I had to restart the computer, as everything became too slow.
When I returned to Matlab, I have noticed a strange phenomenon: to my horror, everything became 3 times slower than before. Nothing helped:
  • Restarting the computer;
  • Restarting Matlab;
  • Rehashing toolboxes;
  • Removing prefdir;
  • Running disk defragmentation;
  • Running cleanup programs;
  • Even reinstalling Matlab (!) did not help.
Before I continue, I need to emphasize an important point. I have noticed this hindrance in Matlab's speed only because I was probing the run-time to begin with. Impedance of a factor of 3 is not substantial enough to notice in naked eye. Yet, it is a very significant change rendering most of the simulations useless. It could have been weeks before I had noticed something was wrong, and by then it would have been too late, as there would be nothing to compare to. @Sean de Wolski, I believe it is a crucial bug in Matlab that must be addressed.
Finally, what has worked is the following.
  1. Draining the battery of my laptop (Dell Vostro).
  2. Running Dell System Diagnostic Tool at the boot-level. I ran it twice, just in case, with all the options on (with emphasis on memory and cores).
  3. Rebooting the computer.
Matlab is now back to its fast self. Yet, I have no idea why it has succeeded. This behavior should not exist in a ubiquitous program such as Matlab.

  0 Comments

Sign in to comment.


Answer by Richard
on 31 Dec 2013

Could my Java files have been corrupted somehow? If I wanted to replace the java files related to MATLAB (it uses it's own JRE or JDK right, not the one installed under windows programs?) how would I do that? Is there a way I can run a fix tool on it?

  0 Comments

Sign in to comment.


Answer by Sean de Wolski
on 31 Dec 2013

I would recommend first just upping your Java Heap Space. This is the first thing to do for desktop sluggishness.
Go to:
Home Tab - Preferences - MATLAB - General - Java Heap Memory.
Bump this up, apply and restart MATLAB.
Also, make sure you do not have any network directories on your path and that you are not trying to navigate to one in startup.m

  3 Comments

Yeah the first thing I did was increase the Java Heap Memory. It had no effect. Nothing has changed in my startup.m file between the pre-crash when MATLAB was working perfect and post-crash when it barely works. On top of that, my startup.m file is empty.
How about your path? Any network directories?

Sign in to comment.


Answer by Richard
on 31 Dec 2013

Even the help function is slow. If I try and do 'help plot' it takes a good 10 seconds for the action to occur. I really could use some help with this MATLAB admins.

  2 Comments

Maybe I'm not being clear. There is no program running. This is a MATLAB issue, not a script or function issue.
For example, if you type in your command window the following '2 + 2', you will quickly get the output '4'. If I do that in my command window, I have to wait 10 seconds for the answer.
Example 2: If you type 'help plot' in your command window, you will quickly get the details of how the plot function works and what parameters it can take as input. If I type that in my command window, I have to wait 15 seconds for the output.
Example 3: If I try and run a script, I have to wait 10-20 seconds for the script to begin running. It does not matter how complicated the script is. The script could be as simple as 'y = 2; x = 3; z = x + y' and I will have to wait the minimum 10-20 seconds for it to complete.

Sign in to comment.