I have the below loop (code simplified) :
for (int y = 0; y < 20; y++) {
self.array[y].numbers = [self getNumberData:source objectPass:object];
}
This calls the get NumberData method. In this code a malloc method is used, e.g :
object->item1 = malloc(sizeof(Class) * object->item2);
My question is how do I correctly free up the malloced memory ?
The self.array[y].numbers is a C struct.
Can I just put free (array) in the dealloc method ?
Thank you.
You must pass the pointer returned by
malloctofree.So, if you’ve
malloced up the whole array of structs in one swell foop, you can (and must)freethe whole thing, as well.If you’ve
malloced each struct individually, you mustfreeeach, as well.