Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Cell Array of Function Handles Leaks Memory
Date: Sun, 1 Jun 2008 15:21:01 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 35
Message-ID: <g1ueot$67i$1@fred.mathworks.com>
References: <g1t973$aeg$1@fred.mathworks.com> <g1tkd6$qi9$1@fred.mathworks.com> <g1udna$sgp$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1212333661 6386 172.30.248.35 (1 Jun 2008 15:21:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 Jun 2008 15:21:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:471639



"NIcholas ":
<SNIP down to partial answer...

> Does MATLAB store copies of all variables in the local 
scope when creating an anonymous function...

yes, as can be seen here

% create a dummy function
function r=foo
     b=ones(100);
     r.f=@(x) x=1;
end

% at the command prompt
     f=foo;
     whos f
% f 1x1 140 struct <- apparently small
     ff=functions(f.f);
     whos ff
% ff 1x1 81090 struct <- reveal the truth
     ff
%{
     function: '@(x)x+1'
     type: 'anonymous'
     file: 'YOURPATH\foo.m'
     workspace: {2x1 cell}
%}
     ff.workspace{2}
%{
     r: [1x1 struct]
     b: [100x100 double] % in foo's ws at time of creation
%}

us