On Mar 8, 2015, at 10:00 PM, Patrick J. Collins <[email protected]> 
wrote:
> 
> +(void)translatCoefficients... {
>    ... stuff that calculates k[1] through k[10] and rms
>    double k[11] = {0};
> 
>    NSLog(@"%f", k[1]);  // this outputs ==>  -0.941884
> 
>    return [[Reflector alloc] initWithKs:k rms:rms];
>  }

When you define an array by typing "type name[count]”, you’re creating that 
array on the stack. Variables allocated on the stack go away as soon as they 
fall out of scope. So when -[Reflector initWithKs:rms:] is running, the array 
is still valid, but as soon as +translateCoefficients... returns, k is getting 
deallocated. If you’ve hung onto it somewhere, it’s now garbage. So yes, 
copying the array is something you’ll need to do. You could use memcpy() 
instead of the loop though, to make it a little more concise.

Charles

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/objc-language/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to