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?

Answer by Yair Altman
on 1 Jan 2014

Edited by Yair Altman
on 1 Jan 2014

Several possibilities spring to mind:

- Your antivirus is running wild ( link1, link2, link3 )
- You are using a CVS (code-versioning system) that is ill-configured
- 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
- You have clashes with other software that uses the same FLEXnet license manager as Matlab ( link1, link2 )
- You have mapped drives that are disconnected for some reason but Matlab doesn't know this
- You have a very long Matlab path
- You have defined a function somewhere on the Matlab path that has a name which overrides some internal Matlab function
- Your Matlab installation is critically fragmented on disk (=> run a defragmetation utility)
- You are using a toolbox that is ill-configured (e.g., symbolic toolbox)
- You are running Matlab via an X-server or SSH
- You have disabled toolbox caching in the global Matlab preferences
- You have defined numerous workspace variables
- You have numerous files loaded in the Editor
- You have multiple open figure windows
- You are using SELinux without setting the allow_execheap flag (so JIT is disabled)
- You are using a vast number of Windows fonts
- You are using unnecessary web-proxy auto-discovery
- 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.

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

Richard
on 31 Dec 2013

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.

Richard
on 31 Dec 2013

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.

- Draining the battery of my laptop (Dell Vostro).
- 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).
- 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.

Sign in to comment.

Answer by Richard
on 31 Dec 2013

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

Richard
on 31 Dec 2013

Sean de Wolski
on 31 Dec 2013

How about your path? Any network directories?

Richard
on 31 Dec 2013

No, all local.

Sign in to comment.

Answer by Richard
on 31 Dec 2013

Walter Roberson
on 31 Dec 2013

Perhaps profiling would help narrow the problem.

Richard
on 31 Dec 2013

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.

Opportunities for recent engineering grads.

Apply Today
## 5 Comments

## Sean de Wolski (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/111060-after-allocating-a-large-variable-and-crashing-matlab-is-forever-slow#comment_187722

## Richard (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/111060-after-allocating-a-large-variable-and-crashing-matlab-is-forever-slow#comment_187728

## Sean de Wolski (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/111060-after-allocating-a-large-variable-and-crashing-matlab-is-forever-slow#comment_187736

## Richard (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/111060-after-allocating-a-large-variable-and-crashing-matlab-is-forever-slow#comment_187755

## Angga Lisdiyanto (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/111060-after-allocating-a-large-variable-and-crashing-matlab-is-forever-slow#comment_372247

Sign in to comment.