How can I solve memory leak in fft?
8 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Steve Eddins
2013-1-28
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 个评论
John D'Errico
2014-12-9
编辑:John D'Errico
2014-12-9
This would suggest the value of a 'nocache' option in fft.
Noah Prisament
2023-6-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!