Calling mex sub-routines - runs out of memory? Any specific destroyArray required for prhs after using it?

Most of my code is like the code sample below. It runs out of memory after a few thousand calls. Although my main work space is not occupying any memory. Looks like most of these sub-routine calls ends up not freeing any of its memory used. So eventually memory runs out after matlab reaches its process limits. Should I explicitly free up prhs or those small double arrays that I declare for usage internally?
#include "mex.h"
#include "timeConversions.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
double *utcTimeVec, *ut1TimeVec, *eopDataArray;
int nRecords;
if(nrhs < 2)
{
printf("\n Insufficient input \n USAGE: [ut1TimeVec] = utc2UT1_VerC(utcTimeVec, eopDataArray)\n");
return;
}
utcTimeVec = mxGetPr(prhs[0]);// 1x6 array
eopDataArray = mxGetPr(prhs[1]); // 100x7 array
nRecords = mxGetM(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(1, 6, mxREAL);
ut1TimeVec = mxGetPr(plhs[0]);
utc2UT1(utcTimeVec, eopDataArray, nRecords, ut1TimeVec);
}
Do I have to explicitly deallocate or destroy anything before exiting?
K

Answers (1)

No, you should not be calling mxDestroyArray for any of the prhs after using them. What does the utc2UT1 routine look like? Are you sure you are passing in the correctly sized and typed arrays?

3 Comments

Thanks for the quick reply. The function call returns just fine for a few thousand calls. But over time, I can see memory usage increasing. Should I take care of clearing any locally declared variables or free up pointers within mexFunction above?
The only allocation I can see in the above code is the mxCreateDoubleMatrix call. You obviously don't want to destroy that before returning since it is being used for plhs[0]. I see nothing else allocating any memory so there is nothing else to free up. Which is why I asked about what the utc2UT1 routine is doing. Also, what is happening at the MATLAB m-file level? Is there something happening there that might be using up memory (e.g., plots, etc).

Sign in to comment.

Categories

Tags

Asked:

on 6 Feb 2014

Commented:

on 6 Feb 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!