Simulink Model Memory Leaks
조회 수: 2 (최근 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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!