From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: why does Matlab fail to release memory even if I clear all the variables?
Date: Mon, 1 Mar 2010 13:47:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 16
Message-ID: <hmgggp$r5e$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1267451225 27822 (1 Mar 2010 13:47:05 GMT)
NNTP-Posting-Date: Mon, 1 Mar 2010 13:47:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1411057
Xref: comp.soft-sys.matlab:612689

The program occupies increasing memory storage and the computer becomes slower and slower... finally, the error of "out of memory" happens. However, during the running of the program, no new variable is created. Why does the program needs an increasing memory? 

Possibly, I think, this may be caused during calling 'myfcn' in a nested loop. So, I test it with some simple codes: for n=1:10000, p=myfcn(C,ph); end. That veritified my judgement. BTW, function 'myfcn' is the only function involving symblic operation.

function [pzs] = myfcn(C, ph)
syms pz
ph  = real(ph);
P    = [ph,pz; -pz,ph];
CM = P * C * P.'; 
eq  = det(CM-eye(2));
cc   = sym2poly(eq);
pzs = roots(cc);

Another problem I'm confusing is that even after I clear all the variables by executing "clear", the memory are not released.