Search code examples
iphonensarrayretain

many retains placed on NSURL when using arrayWithContentsOfURL


I am creating an NSArray from a URL that points to a plist

NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[1]"
content = [NSArray arrayWithContentsOfURL:_url];
NSLog(@"_url rc:[%d]",[_url retainCount]); //prints "_url rc:[10]"

I'm completely at a loss as to why this is occurring. Let me know if you need further information.


Solution

  • Do not call -retainCount.

    The absolute retain count of an object is useless unless your code is the only thing that has ever touched the object. As soon as you pass the object through system API's the absolute retain count is no longer something you have any control over.

    As chrissr implied, the retain count of an object should be treated entirely as a delta. If you cause it to be increased, you should cause it to be decreased. If you retain, you must release. If you copy, you must release. Etc...