0

I'm using VLFeat to train a Gaussian Mixture Model(GMM), and I'm not sure if I should manually free memory when the following commands are used:

float *means = (float *) vl_gmm_get_means(gmm);
float *covariances = (float *) vl_gmm_get_covariances(gmm);
float *priors = (float *) vl_gmm_get_priors(gmm);

Do I have to manually write codes like the following?

free(means);
free(covariances);
free(priors);

Thanks!

Lotayou
  • 162
  • 11

1 Answers1

0

Don't know what you mean by "let Visual Studio do its job'...

If memory is allocated, it needs to be freed. C++ is not a garbage collected language so all memory allocation/deallocation is explicit through new/delete (or malloc/free).

I have never used the library (VLFeat) in question, but I googled its memory allocation functions. My guess, is that you should use vl_free() to free memory returned by the library. The implementation may just wrap free() or some other function, but usually for libs like this, you should use lib functions to manage memory returned from the lib.

The documentation for vl_free() states: This function frees a memory block allocated by vl_malloc, vl_calloc, or vl_realloc. The synopsis is the same as the POSIX malloc function.

Joseph Willcoxson
  • 5,853
  • 1
  • 15
  • 29
  • Thanks. But I'm not sure how the function `vl_gmm_get_means(gmm);` was implemented, since it was a build-in function and source code is not avaliable... Still I could try to `vl_free` anything for safety though... – Lotayou Jan 17 '17 at 05:18