Memory leak in complex griddedInterpolant
Mostra commenti meno recenti
Hello,
I am experiencing a memory leak when loading griddedInterpolant with complex vales multiple times. I have prepared a test script reproducing this issue:
%% complex griddedInterpolant memory leak test
A = complex(rand(5e3),rand(5e3));
% A = rand(5e3);
A = griddedInterpolant(A);
save testfile A;
clear A;
user = memory;
m0 = user.MemUsedMATLAB;
for i = 1:100
load testfile A;
clear A;
user = memory;
disp(user.MemUsedMATLAB-m0);
m0 = user.MemUsedMATLAB;
end
In each step, Matlab displays the increase in user memory from the previous step, which in this case is around 400 MB (likely the size of the complex double array 5e3^2*8*2). After several steps Matlab runs out of memory.
The memory leak does not occur when uncommenting line
A = rand(5e3);
which indicates that the issue occurs with complex numbers only.
Similarly when commenting line
A = griddedInterpolant(A);
there is no memory leak either, so the issue is limited to griddedInterpolant and not just any complex array.
Is this really a bug, or did I miss anything here?
5 Commenti
Bruno Luong
il 10 Ago 2023
I confirm it seems like the leak is real.
Ondrej
il 14 Ago 2023
Benji
il 29 Gen 2024
I have also seen this issue and can confirm the code above also shows a memory leak on MacOS. I also believe, though cannot show simple code to demonstrate this, that using a griddedInterpolant as a property in a handle object shows similar memory leak issues. For large data grids, this problem becomes dramatic, often causing MATLAB to crash.
Andreas Akselsen
il 12 Set 2025
@Benji, I can confirm that you are right.
I further identified the issue as arrising between v. 2023b (no issue) and 2024a (issue).
Here's a quick example where the two loops run about the same on 2023b while the second runs orders of magnitude slower on say 2025a.
clear all
nx = 1000000; dx = .01; nRepeat = 1000;
nIP = 1150;
xIP = rand(nIP,1)*dx*nx;
data = rand([nx,1],'like',1i); % issue disappears instead using real numbers
gi = griddedInterpolant((0:nx-1)'*dx,data);
sc = StructClass();
sc.gi = gi;
tic
for i = 1:nRepeat, b = gi(xIP); end
fprintf('relTime: %.4fms\n',toc*1000/nRepeat)
tic
for i = 1:nRepeat, b = sc.gi(xIP); end
fprintf('relTime: %.4fms\n',toc*1000/nRepeat)
with
classdef StructClass % < handle or not
properties
gi
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Multidimensional Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!