From: Srimal Jayawardena on
Hi

I just profiled the timestwo.c mex example given in the MATLAB documentation at
http://www.mathworks.com/support/tech-notes/1600/1605.html#example2
and noticed that it doesn't free allocated memory.

In the profile report that is saved (and opens up in the web browser automatically - which is very nice :) it says:

Allocated Memory: 1568.00 Kb
Freed Memory: 0.00 Kb

This is even after clearing the two variables returned by the mexFunction as follows.

clear a,b;

Not that I used the example provided in the official mathworks documentation as the mex function.
http://www.mathworks.com/support/tech-notes/1600/1605.html#example2


The matlab code used to test it goes like this:

profile -memory on
one = ones(1000,100);
two = 2*one;
[a b] = timestwo(one, two);
clear a,b;
profile viewer
profsave(profile('info'), 'profiling_results')


Is this a BUG in the mex implementation in MATLAB or is the example in http://www.mathworks.com/support/tech-notes/1600/1605.html#example2 buggy? (or last but not least is the m-code I wrote wrong?)

Either way how can I properly free memory after running a mex Function.

My real application requires calling a mex function many times and it often gives an out of memory error in MATLAB.

Thanks

Srimal.