Welcome! Log In Create A New Profile

Advanced

Out of Memory Error

Posted by marmosets 
Out of Memory Error
March 18, 2021 02:12PM
Hi Jaewon!

I am having some troubles with Java Heap Memory when reading data after certain sessions. When I attempt to run behaviorsummary, the following error reads out: "Error using reshape. Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension." When I attempt to open the BHV2 file, I get an OutOfMemory: Java Heap error. These errors always seem to appear together and I otherwise have no issues using behaviorsummary. The entirety of these errors is below. These errors do no always arise, and seem to when animals likely complete a high number of trials (based on reward received), but this is not always consistent. I have had animals complete 700 trials before with no issue, but on certain occasions I cannot open or run analysis on BHV2 files. After the first two times this error occurred, I increased the Java Heap Memory in Matlab, incrementally up to its maximum as the errors occurred. Even while set at maximum (2015 MB for the machines running ML), I still received the error today.

I have attached the timing and conditions files used during the session in question, as well as a zip of the BHV2 file.

Do you have any advice on how to navigate this error and prevent it from happening? I appreciate any insight you have and apologize if this is merely a result of my inexperience programming.

Thank you!

1 - Behavior Summary Error

"Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

Error in mlbhv2/read_variable (line 277)
val = reshape(fread(obj.fid,prod(sz),['*' type]),sz); % fread can handle only a 2-d size arg.

Error in mlbhv2/read_variable (line 270)
for n=1:nfield, [a,b] = read_variable(obj); val(m).(b) = a; end %#ok<AGROW>

Error in mlbhv2/read_variable (line 270)
for n=1:nfield, [a,b] = read_variable(obj); val(m).(b) = a; end %#ok<AGROW>

Error in mlbhv2/read_trial (line 141)
[a,b] = read_variable(obj);

Error in mlread (line 29)
data = fid.read_trial();

Error in ML_Analyze (line 5)
ML_Data_Log = mlread(log_loc);"

2 - Java Heap:

Error in ML_Analyze (line 5)
ML_Data_Log = mlread(log_loc);

Exception in thread "AWT-EventQueue-0": java.lang.OutOfMemoryError: Java heap space
at org.netbeans.editor.DocumentContent.enlargeGap(DocumentContent.java:208)
at org.netbeans.editor.DocumentContent.insertText(DocumentContent.java:246)
at org.netbeans.editor.DocumentContent$Edit.undoOrRedo(DocumentContent.java:373)
at org.netbeans.editor.DocumentContent$Edit.<init>(DocumentContent.java:317)
at org.netbeans.editor.DocumentContent.insertString(DocumentContent.java:84)
at org.netbeans.editor.BaseDocument.insertString(BaseDocument.java:596)
at com.mathworks.widgets.text.PrintableDocument.insertString(PrintableDocument.java:444)
at com.mathworks.widgets.datamodel.TextFileBackingStore.loadDocumentFromFile(TextFileBackingStore.java:174)
at com.mathworks.widgets.datamodel.TextFileBackingStore.doLoad(TextFileBackingStore.java:241)
at com.mathworks.widgets.datamodel.TextFileBackingStore.doLoad(TextFileBackingStore.java:32)
at com.mathworks.widgets.datamodel.AbstractBackingStore.load(AbstractBackingStore.java:114)
at com.mathworks.mde.editor.EditorView.reload(EditorView.java:410)
at com.mathworks.mde.editor.EditorView.initSyntaxTextPane(EditorView.java:862)
at com.mathworks.mde.editor.EditorView.<init>(EditorView.java:222)
at com.mathworks.mde.editor.EditorView.<init>(EditorView.java:153)
at com.mathworks.mde.editor.EditorViewClient.init(EditorViewClient.java:226)
at com.mathworks.mde.editor.EditorViewClient.<init>(EditorViewClient.java:175)
at com.mathworks.mde.editor.MatlabEditorApplication.createEditorViewClient(MatlabEditorApplication.java:703)
at com.mathworks.mde.editor.MatlabEditorApplication.createEditorViewClient(MatlabEditorApplication.java:688)
at com.mathworks.mde.editor.MatlabEditorApplication.createEditorViewClientFromExistingFile(MatlabEditorApplication.java:680)
at com.mathworks.mde.editor.MatlabEditorApplication.access$300(MatlabEditorApplication.java:77)
at com.mathworks.mde.editor.MatlabEditorApplication$4.runWithOutput(MatlabEditorApplication.java:405)
at com.mathworks.jmi.AWTUtilities$Invoker$2.watchedRun(AWTUtilities.java:475)
at com.mathworks.jmi.AWTUtilities$WatchedRunnable.run(AWTUtilities.java:436)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
Attachments:
open | download - Visual_Discrimination_Task_NoInitiation_100%Conflict_Stage3.4.txt (4.1 KB)
open | download - Visual_Discrimination_Task_NoInitiation.m (6.3 KB)
open | download - 20210318_Griffin_100%Con_ThreeBlocks_SetChange.bhv2.zip (1.87 MB)
Re: Out of Memory Error
March 19, 2021 03:36PM
Your file is corrupted. I can read up to Trial 567 but then the file ends in the middle of the touch data of Trial 568. I modified mlread to return any readable portion. Please update your NIMH ML, if you want to try it.

The file seems to have been closed abnormally. Did you finish NIMH ML normally when you saved it? Trial 568 is almost as long as the sum of the other 500 trials, so I wonder if you just left the program until it crashed with an out-of-memory error.

You cannot fix memory shortage just by changing some options. You should install more memory to the computer or change something to decrease memory usage. Speaking of which, you recorded 10 touches although your task did not seem to require multi-touch. If it was not intended, that is a huge waste of memory and disk. I think changing the number to 1 will probably fix most of the issues.
Re: Out of Memory Error
March 30, 2021 12:46PM
Hi Jaewon!

Thank you for looking into this for me. The new update works great for what I need.

Yes - that sounds correct. In our situation, the tablet battery will die if I do not promptly get back to the vivarium and may be left there for a duration of time. Monkeylogic usually opens back up to the subject screen when the tablet is powered back on and reads as if the task has continued to run. It seems likely that this caused the crash based on what you have told me.

I have set the multi-touch to 10 because the animals tend to lean on the screen, sometimes touching independently with multiple appendages. By enabling multi-touch, I have been able to have the animals continue to interact with the tablet despite differing body orientations. So far this is the best solution I have found, but perhaps a better one exists. I will look into other ways to address memory shortage.

Thank you again! I appreciate the help!
Re: Out of Memory Error
March 30, 2021 01:38PM
You can at least save some disk space by using BHVZ, instead of BHV2. The number of touches simultaneously recorded in your file was not more than 4. So you can still set it to 5 and decrease memory usage by half, I think.
Re: Out of Memory Error
April 05, 2021 01:32PM
Thank you for the advice! I will test the implementation of those options!

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.