memory leak in C Mex file
Afficher commentaires plus anciens
Hello,
I wrote a C mex script, and it runs, however, after running it several times, it crashes Matlab, meaning that there is a memory leak somewhere.
This is the first time I tried to pass into the MEX routine a 2D matrix, so it's probably what's causing the problem.
The 2D matlab matrix is called "connectivity"
Within mexFunction I define the following:
connectivity_pointer = (double *) mxGetPr(prhs[9]);
/*create 2D array for connectivity */
connectivity_M = mxGetM(prhs[9]);
connectivity_N = mxGetN(prhs[9]);
connectivity = mxCalloc(connectivity_N,sizeof(double*));
for (j=0;j<connectivity_N;j++){
connectivity[j]=connectivity_pointer+connectivity_M*j;
}
/*do stuff*/
mxFree(connectivity);
return;
Is this correct?
I have no idea what it could otherwise be.. On a side note, I have the new Yosemite, Matlab 2014b, and XCode 5.0, and every time I try to create a MEX debugging session with XCode it crashes (even before attaching processes)! Anyone experienced that?
Francesco
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!