I have a method that receives an array and then stores this in the NSObject properties.
- (void)updatePoints:(NSArray *)pointArrayPassed
{
pointArray = pointArrayPassed;
pointCount= pointArray.count;
}
The following code works but obviously keeps the pointer of pointArrayPassed so when I can that it reflects down the call stack. However if I use a copy of the pointArrayPassed then the app starts to leak heavily!
Is there a way in the function to pass just the values as such instead of the pointer?
You can’t just keep sticking copies in an iVar without releasing the current object. Otherwise you’ve lost the pointer to which you can send the
releasemessage – which is why it leaks all over the place.This is a better replacement.
But it’s not the most elegant way of doing it.
A better way is to declare pointArray as an property with
copyas its memory management semantic (which is obvious as you have a mutable/immutable class cluster). And have a separate method called-pointCountwhich returns the count when required.