I'm trying to mimic the following Java code:
int[][] multi; // DIMENSIONS ARE UNKNOWN AT CREATION TIME
// LATER ON...
multi = new int[10][];
multi[5] = new int[20];
multi[5][11] = 66;
// LATER ON...
multi = null; // PROPER WAY OF FREEING EVERYTHING
I've came out with the following Objective-C version:
int* *multi;
//
multi = malloc(10 * sizeof(int*));
multi[5] = (int *) malloc(20 * sizeof(int));
multi[5][11] = 66;
//
free(multi[5]);
free(multi);
So first, I'd like to hear if it's the best way to go. And mostly: I can't find a way to free memory in some "automatic" fashion, i.e. the following code is causing run-time exceptions on the IPhone:
for (int i = 0; i < 10; i++)
{
if (multi[i] != NULL) free(multi[i]);
}