Reputation: 21
I am working on activity recognition but am getting an out of memory error
after processing one video.
The maximum possible array turns from 444mb to 84mb, which means it can't process more than one video. Using clear all;
and close all;
we can just clear the matlab memory, but how do we clear the virtual memory (ram) space without closing matlab?
Any help would be much appreciated.
Upvotes: 2
Views: 9821
Reputation: 41
If run-time is not an issue for you, you may try using matfile
that will let you access/load/save your data on your hard drive rather than RAM, but as your would expect, the process might be slow.
Another option that I tried while working on my problem is to convert my data to single
precision, this should reduce the memory consumption by half. For videos and images, I believe that most of the work is doable using single
instead of double
precision. Of course, if you could, then further using them in uint8
will reduce the consumption by 8.
Related to your original problem, I think there is actually no solution for that other than restarting matlab everytime.
Upvotes: 0
Reputation: 21563
If you have to do all of them simultaneously, there probably is not enough memory. However I assume you want to process them sequentially. As mentioned in this question, you may have to resort to closing matlab and restarting it.
This may sound awfull, but with a little work you can ease the pain.
Here are steps you can take:
The last part may not be easy to find, but suppose the function you want to call is magic(5)
, then it would be something like this:
!matlab -r "magic(5)" &
exit
Upvotes: 1
Reputation: 287
Java Heap Cleaner seems to work fairly well. But if you try and call it after you get a "Java heap space" type of error, it may or may not help, I haven't quite figured out if there's a pattern.
Edit: Try also the
pack
command. That forces Matlab to run the garbage collector on its own memory, while the Java Heap Cleaner does the same thing but on the Java memory.
Edit 2: I found out that you don't need to download Java Heap Cleaner to run the JVM garbage collector. You can also go for:
java.lang.Runtime.getRuntime.gc;
That seems to work quite well for me.
Upvotes: 0