MATLAB: Get an error message by running a large code

error message

When I run a large code, I get the following error message, unfortunately I have no idea where it could come from or what I need to do in order to solve that problem. Is there anybody who could help?
Exception in thread "FileDecorationCache request queue" java.lang.ArrayIndexOutOfBoundsException: 2
at java.util.LinkedList.toArray(Unknown Source)
at java.util.ArrayList.<init>(Unknown Source)
at com.mathworks.mlwidgets.explorer.model.table.UiFileList.fireListeners(UiFileList.java:448)
at com.mathworks.mlwidgets.explorer.model.table.UiFileList.access$000(UiFileList.java:43)
at com.mathworks.mlwidgets.explorer.model.table.UiFileList$1.stateChanged(UiFileList.java:118)
at com.mathworks.util.MulticastChangeListener.stateChanged(MulticastChangeListener.java:26)
at com.mathworks.mlwidgets.explorer.model.FileDecorationCache$1.stateChanged(FileDecorationCache.java:101)
at com.mathworks.util.MulticastChangeListener.stateChanged(MulticastChangeListener.java:26)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$2$2.run(FileDecorationModel.java:299)
at com.mathworks.mlwidgets.explorer.extensions.basic.DefaultFileInfoProvider$1.run(DefaultFileInfoProvider.java:64)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$3$1.run(FileDecorationModel.java:342)
at com.mathworks.util.RequestQueue.execute(RequestQueue.java:105)
at com.mathworks.util.RequestQueue.access$000(RequestQueue.java:23)
at com.mathworks.util.RequestQueue$2.run(RequestQueue.java:76)
at java.lang.Thread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.mathworks.mlwidgets.explorer.util.FileSystemUtils.readBytes(FileSystemUtils.java:469)
at com.mathworks.mlwidgets.explorer.util.FileSystemUtils.readText(FileSystemUtils.java:449)
at com.mathworks.mlwidgets.explorer.util.FileSystemUtils.readText(FileSystemUtils.java:437)
at com.mathworks.mlwidgets.explorer.extensions.matlab.MFileTypeFinder.findMFileType(MFileTypeFinder.java:29)
at com.mathworks.mlwidgets.explorer.extensions.matlab.MFileInfoProvider$1.run(MFileInfoProvider.java:68)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$DeferHandler.run(FileDecorationModel.java:389)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$2.get(FileDecorationModel.java:274)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$1$2.run(FileDecorationModel.java:183)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$DeferHandler.run(FileDecorationModel.java:389)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$2.get(FileDecorationModel.java:274)
at com.mathworks.mlwidgets.explorer.util.UiFileSystemUtils.getDecorationSynchronously(UiFileSystemUtils.java:125)
at com.mathworks.mlwidgets.explorer.util.UiFileSystemUtils.getDecorationSynchronously(UiFileSystemUtils.java:98)
at com.mathworks.mlwidgets.explorer.model.table.FileSystemExpansionProvider.getDecoration(FileSystemExpansionProvider.java:124)
at com.mathworks.mlwidgets.explorer.widgets.table.FileTable.getDecoration(FileTable.java:738)
at com.mathworks.mlwidgets.explorer.DetailViewer$5.run(DetailViewer.java:200)
at com.mathworks.mwswing.MJUtilities.runOnEventDispatchThread(MJUtilities.java:865)
at com.mathworks.mlwidgets.explorer.DetailViewer.setFile(DetailViewer.java:177)
at com.mathworks.mde.explorer.Explorer$5.valueChanged(Explorer.java:300)
at com.mathworks.widgets.grouptable.GroupingTable.fireSelectionListenersIfEnabled(GroupingTable.java:550)
at com.mathworks.widgets.grouptable.GroupingTable.access$300(GroupingTable.java:56)
at com.mathworks.widgets.grouptable.GroupingTable$17.valueChanged(GroupingTable.java:539)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.setValueIsAdjusting(Unknown Source)
at com.jidesoft.grid.JideTable$15.setValueIsAdjusting(Unknown Source)
at com.mathworks.widgets.grouptable.GroupingTable$25.run(GroupingTable.java:776)
at com.mathworks.mwswing.MJUtilities.runOnEventDispatchThread(MJUtilities.java:865)
at com.mathworks.widgets.grouptable.GroupingTable.restoreSelection(GroupingTable.java:709)
at com.mathworks.widgets.grouptable.GroupingTable.access$1000(GroupingTable.java:56)
at com.mathworks.widgets.grouptable.GroupingTable$18.run(GroupingTable.java:574)
at com.mathworks.widgets.grouptable.GroupingTable$18.run(GroupingTable.java:558)
at com.mathworks.widgets.grouptable.GroupingTableModel.refresh(GroupingTableModel.java:689)
Exception in thread "Timer-1" Exception in thread "AddressBar directory emptiness poller" Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Exception in thread "Explorer NavigationContext request queue" java.lang.OutOfMemoryError: Java

Best Answer

You are running out of Java heap space.
Two solutions:
[1] Increase the size of the available heap in MATLAB preferences.
[2] Delete objects that you do not need.
You can monitor the state of the heap space by running jconsole - part of the Java distribution and connecting it to the JVM for a running MATLAB session (which will likely appear without a title in the drop down list provided by jconsole at start up).