How can I solve memory leak in fft?

When using fft function many times with different input size it causes memory leak (as seen in the physical memory).
For example, the following matlab code :
for i=1:1000, y=fft([1:i*1000]); end
MATLAB Version: 7.14.0.739 (R2012a)
How can I solve it?

답변 (1개)

Steve Eddins
Steve Eddins 2013년 1월 28일

1 개 추천

It is not an actual memory leak. MATLAB does cache (save for reuse) tables of trigonometric values for use in subsequent calls to FFT with vectors of the same length. (There is a significant performance benefit in doing so.) However, this cache does have a finite size; it will not continue to grow indefinitely.

댓글 수: 4

Shmuel
Shmuel 2013년 1월 29일
Thank you for your fast replay. However when running the full program the memory reaches 99% (16Gb in total) and it slows dramatically (due to running many times FFT with vectors in different size). Only by closing MATLAB the memory is released. From your answer I understand I need to release the cache somehow or to restrict it from growing. Can you direct me how to do that?
David
David 2014년 12월 9일
I am performing ffts and iffts on large arrays >4GB. However, because the matlab memory footprint grows after the initial calls to fft and ifft, the usable memory for variables decreases. Because the arrays are very large to begin with, this causes issues maxing out the computer's memory. Is it possible to clear this fft cache without restarting matlab? For cases like this, low memory overhead is more important than execution speed.
John D'Errico
John D'Errico 2014년 12월 9일
편집: John D'Errico 2014년 12월 9일
This would suggest the value of a 'nocache' option in fft.
To clear this cache, you can utilize the "fftw" command which is used to modify the settings and behavior of the "fft" function. You can execute the following commands in your scripts or in the command window to clear the cache:
fftw('swisdom', []);
fftw('dwisdom', []);
These will clear the single precision and the double precision caches respectively. Another important command to minimize the memory usage of the "fft" function is:
fftw('planner','estimate');
as the other planner options employ more memory in order to improve their precision. More information on the "fftw" command can be found here.
These uses of "fftw" should help with limiting the size of the cache and releasing it periodically.

댓글을 달려면 로그인하십시오.

질문:

2013년 1월 28일

편집:

2026년 6월 3일 18:13

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by