Simulink Model Memory Leaks
8 次查看(过去 30 天)
显示 更早的评论
My model seems to leak memory, and of course becomes painful to use when it gets to the stage that doing so has to involve swap. I can see the memory usage gradually increase from arounf 3G to 8G over a day in the task manager when I am running the model.
I suspect these routines I wrote for sending variable length UDP messages. Previously I was using UDP Send blocks which do not appear to support variable lenght messages.
This routine is invoked every simulation time step.
I have put comments in where I would like to call "clear" to be sure to free the memory.
Is there a memory leak here, and how do I fix it, either by clearing the memeory or avoiding the allocations?
function [data,status]=receive_message
coder.extrinsic('evalin');
coder.extrinsic('getfield');
coder.extrinsic('fread');
n=zeros(1,1,'double');
data=zeros(1,350,'uint32');
BMS_link_1=evalin('base', 'MyUDPObject');
n=getfield(MyUDPObject,'BytesAvailable');
if n>0
status=1;
tmp=fread(MyUDPObject,1,'int32');
w=uint32(0);
w=uint32(numel(tmp));
%fprintf('Msg_ID: %i Len: %i\n',tmp(1),w);
for i=uint32(1):w
data(i)=tmp(i);
end
%clear tmp; % cannot be used, clear is not supported for code generation.
%clear w;
else
status=0;
end
%clear n;
end
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!