Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1267451225 27822 172.30.248.37 (1 Mar 2010 13:47:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 1 Mar 2010 13:47:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1411057
Xref: news.mathworks.com 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.