views:

23

answers:

1

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.

+2  A: 

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...

bbum
I appreciate the help, I was just curious as to why it shot to 10.
Bryan Clark
because the framework wants to ensure the `NSURL` object stays around even if you release it. :-)
Franci Penov
why thank you framework :)
Bryan Clark
If I were to guess, `arrayWithContentsOfURL:` is doing some kind of recursive parse of the document and the `_url` is being retained/autoreleased possibly by a caching mechanism and problem a few times as the parse occurs (as DTDs are read and the like).
bbum