Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
No way to release memory used by anonymous functions

Subject: No way to release memory used by anonymous functions

From: othree

Date: 30 Sep, 2010 12:02:05

Message: 1 of 1


I'm using matlab to generate lots of functions and find the best one fits for my data.
Most of the functions are only used for one time (executes about 100 times).
So I use anonymous function instead of inline function. Which is faster about 8 times.
But anonymous function will lock some memory and can't be release.
I will produce about 5000*200 functions for each search. And they will exhaust all my memories.

Is there any way to clear all anonymous functions in memories ?

I wrote a simple code to see the problem.

for i=1:10e3; y=str2func(['@(x) x*x*' num2str(i)]); end

Execute this line of code and see the change of the memories used by matlab.
This line of code will produce 1000 different anonymous functions and use about 100 MB memories. And there is noway to release these memories.

I have tried 'clear all', 'clear functions' and execute 'clear y' in for loop.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us