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:56:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 56
Message-ID: <g1ugqh$ip1$1@fred.mathworks.com>
References: <g1t973$aeg$1@fred.mathworks.com> <g1tkd6$qi9$1@fred.mathworks.com> <g1udna$sgp$1@fred.mathworks.com> <g1ueot$67i$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 1212335761 19233 172.30.248.35 (1 Jun 2008 15:56:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 Jun 2008 15:56:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1327593
Xref: news.mathworks.com comp.soft-sys.matlab:471641



"us " <us@neurol.unizh.ch> wrote in message
<g1ueot$67i$1@fred.mathworks.com>...
> % create a dummy function
> function r=foo
>      b=ones(100);
>      r.f=@(x) x=1;
> end

I assumed this should be x+1, since x=1 gives illegal
assignment error.

> % 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}
> %}

I get the same result for whos f, but I get different
results for ff:
whos ff
% ff  1x1 572  struct array

ff
%{
function: '@(x) x+1'
         type: 'anonymous'
         file: 'C:\MATLAB7\work\foo.m'
         workspace: [1x1 struct]

%}

ff.workspace
%{
1x1 struct array with no fields.
%}

However, changing the function to: r.f=@(x) x+b;
I get something similar:
whos ff
% ff 1x1 80696  struct array
ff.workspace
% b: [100x100 double]