Question: i have a little question in relation to the free() function of C.

I allocate in a program a multidimensional array with this code :

```
char **newMatrix( int N ){
    int i,j;
    char **a = malloc(sizeof *a * N);
    if (a)
    {
      for (i = 0; i < N; i++)
      {
        a[i] = malloc(sizeof *a[i] * N);
      }
    }

```

at the end of the program the array is full of characters. 
So i do this to deallocate the memory.

```
void freeArray(char **a, int m){
    int i;
    for (i = 0; i < m; ++i) {
        free(a[i]);
    }
    free(a);
}

```

My question is , how can I really check if the free() function works well , and deallocate all the memory? 
I ask you because I have tried to print the matrix after the freeArray , and the result is that the values are still stored in the a[i][j] columns and rows .

Sorry if it will be a stupid question , i'm new of C programming!

Answer: 
`free` does not mean that it will actually delete the memory! It will inform to the OS that I don't want this memory any more, use it for some other process!

You can certainly continue to use array `a` after calling `free(a)` and nothing will stop you. However the results will be completely undefined and unpredictable. It works by luck only. This is a common programming error called "[use after free](https://cwe.mitre.org/data/definitions/416.html)" which works in many programs for literally years without "problems" -- until it causes a problem.

There are tools which are quite good at finding such errors, such as [Valgrind](http://valgrind.org/).
If I understood you correctly you want to check if:

* You don't reuse memory after freeing it
* You freed all of the memory

It's not possible to do it directly from within language - however there are tools which can help. For example [Valgrind](http://valgrind.org/) can check both of those things (and much more). If you are on Windows tools like [UMHD](http://msdn.microsoft.com/en-us/library/windows/hardware/ff558947(v=vs.85).aspx) can be helpful but I haven't found any freeware replacement (though see also ["Is there a good Valgrind substitute for Windows?" question](https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows))