Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning float array in Objective-C

I would like to know how to return float array in methods.

In methods like:

- (float *) ......{
    float * result = malloc(sizeof(float) * number);
    ....
    return result;
}

My problem is that I didn't clean result float array. How can I do that?

like image 370
Marko Zadravec Avatar asked Oct 02 '22 03:10

Marko Zadravec


1 Answers

My problem is that i didn't clean result float array.

That's the job of whoever is calling your method that returns the float array: now he owns it, so he must call free on it.

Generally, there are two situations:

  • You use the array inside another method or a function without storing it - In this case, identify the point in your method or a function where the array is no longer needed, and call free() passing it the array.
  • You store the array as an instance variable in one of your objects - In this case, add a dealloc method to your class, and call free() on the array variable from there.
like image 104
Sergey Kalinichenko Avatar answered Oct 13 '22 10:10

Sergey Kalinichenko