"Out of memory" error when computing TF on sources when previously it worked fine

Hi.

I scripted a time-frequency decomposition on sources with Morlet wavelets (EEG data, 64 channels), averaging on four frequency bands: alpha (8-12 Hz), beta1 (13-19 Hz), beta2 (20-25 Hz) and beta3 (26-30 Hz). It worked just fine, until it stopped working for apparently no reason. If I average on 3 frequency bands instead of 4, it works. I have a 32GB RAM, so that could be the reason? But I really don't understand why it worked perfectly before. The script hasn't changed, it just stopped working after a bunch of subjects. It doesn't work even when cleaning MATLAB workspace, or by rebooting the computer. I also tried running the same script on a subject on which it already worked and it gives me the same error. I don't see anything using up RAM space differently from before.

Any ideas on what the reason may be?
Thanks

Hi Simone,

I'm sorry I won't be able to help much without any reproducible behavior... Computers have sometimes behaviors that are completely irrational...
There might have been some change on your system, leading to Matlab having less contiguous memory to allocate large variables. You can check the size of the largest variable that Matlab can allocate at the bottom of the Brainstorm preferences window, or directly with Matlab function memory().

You could also check the memory usage while your script is running by opening the resource monitor of your OS.
I haven't checked if this still works with recent Matlab versions, but previously it was also possible to have a very detailed report on the memory allocations with the Matlab profiler:
https://undocumentedmatlab.com/blog/profiling-matlab-memory-usage
https://www.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html

Note that Brainstorm may keep in memory some temporary objects for faster opening/processing, and this might fill up the memory progressively. You can force unloading all the subjects, the equivalent of clicking on the the cross at the top-right corner of the Brainstorm window, by calling:
bst_memory('UnloadAll', 'Forced');

After this advanced debugging, let me know if you think there are issues with the memory management in scripts.

Cheers,
Francois

Hi Francois,

I tried something more drastic: I thought that the reason may be in some recent Windows updates (I operate on a Windows, yes), so I restored system settings before the updates and tried running the script. It now works, so it definitely has to do with some processes after the updates using more RAM resources.

I should have thought about that before posting, sorry.
And thanks for the tips, I'll make use of them in case of future issues :slight_smile:

Best,
Simone