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:03:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 53
Message-ID: <g1udna$sgp$1@fred.mathworks.com>
References: <g1t973$aeg$1@fred.mathworks.com> <g1tkd6$qi9$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1212332586 29209 172.30.248.37 (1 Jun 2008 15:03:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 Jun 2008 15:03:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1327593
Xref: news.mathworks.com comp.soft-sys.matlab:471637



"Bruno Luong" <b.luong@fogale.fr> wrote in message
<g1tkd6$qi9$1@fred.mathworks.com>...
> "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message
> <g1t973$aeg$1@fred.mathworks.com>...
> 
> > A = cellArrayFunHandleLeaks; clear A;
> > 
> 
> Can you use "clear all"? I'm not sure what Matlab doing for
> keeping last current commant prompt, debugging information,
> "precompiled" code, path, etc ... Beware about interpreting
> "MATLAB memory".
> 
> > 
> > Has anybody else had this problem or know of a solution or
> > of a better way to store a set of function handles?
> > 
> 
> Alternatively, you can put it in a structure array.
> 
> Bruno


Hi Bruno thanks for your suggestions.

I run into similar problems using a structure array to store
variables:

function A = cellArrayFunHandleLeaks
B = ones(1000,1000);
A.f = @(x) x+1;
%A{1} = @(x) x+1;
%A = @(x) x+1;

A = cellArrayFunHandleLeaks; clear all;
gives a similar problem, and so does running the first
commented line instead.  The last commented line runs fine
though.

Also, I am not even using B in the anonymous function.  Does
MATLAB store copies of all variables in the local scope when
creating an anonymous function?

The following code without the clear B line has a similar
problem, but with clear B (even after anonymous function
declaration) it works fine.

function A = cellArrayFunHandleLeaks
B = ones(1000,1000);
A{1} = @(x) x+1;
clear B;