small medium large xlarge

Generic-user-small
18 Dec 2009, 21:54
patrick collins (9 posts)

I was a bit thrown off as to why grossSales needed to be retained… It’s a property just like Title, Year, or Rating, those did not require retaining, so why does grossSales?

I felt that the screencast was not very clear on when to use @property(retain) vs. @property(copy) vs. @property(assign).. Nor did it mention anything about the other attributes that the @property declaration uses “nonatomic” / “atomic” / “readwrite” / etc.

I gotta say I am a bit disappointed… I feel that I already understood the basics prior to watching this screencast, and was hoping to get some deeper clarity and have some of my unanswered questions addressed, but… It didn’t really happen.

If only it would have done something like:

“let’s take @property(…) int year and set that to [assign, copy, retain] and by doing this, it means that …….. and that we can see this by going over here and looking at ……… “ etc

-patrick

Generic-user-small
05 Jan 2010, 01:03
David Wilson (11 posts)

Hi Bill…

Great screencast. Thank you.

Like the post before this one, I too am confused about why grossSales was retained. I’d like to understand why grossSales would be retained and title is not. IN the examples I’ve seen in books (prior to Obj-C 2.0) their getters/setters all coded release/retain in the set methods.

  • David
Biopic_100x100_pragsmall
05 Jan 2010, 03:01
Bill Dudney (917 posts)

Hi David,

Sorry its confusing, I can’t find a place in the code that has this line. Could you give me some more to go on that would help me find out what is causing the problem?

Thanks and good luck!

Generic-user-small
05 Jan 2010, 07:18
David Wilson (11 posts)

Hi Bill..

In screencast #2, 22:14, you add the code “grossSales = [newGrossSales retain];

I understand (I think) what’s going on, and certainly understand that the retainCount is incremented by one, and that as you explain later this code should be prefixed with a release to stop the memory leak.

What I want to know is why this style of code was not adopted for the “title” of the movie. (possibly a mute point now that the @property is used for those). No… hang on. at 6:09 title is set with the following code - title = [newTitle capatilizedString]. So the question is what does this not have a release/retain (or should it?).

  • David
Biopic_100x100_pragsmall
05 Jan 2010, 16:05
Bill Dudney (917 posts)

Hi David,

At 22:43 I talk about why we are using retain. Is the problem with title and grossSales not looking the same?

The example is all about why and how you implement dealloc.

If your property uses copy or retain you need to release that value in the dealloc method. If your property uses assign you don’t release.

The title string never has a memory problem because its autoreleased and assigned. So when the pool drains the string is released.

If this does not make sense please let me know.

Good luck!

Generic-user-small
06 Jan 2010, 04:06
David Wilson (11 posts)

Hi Bill… thank you for your patience with this question.

Is the problem with title and grossSales not looking the same?

Yes.

So, you retain grossSales… OK. But title is never issued a retain. So based on your last message here, I don’t need to retain/release title because it is assigned. So therefore what is assign? And if it’s as good as it sounds, why wouldn’t I therefore use it for everything?

I’d be happy to discuss over skype if you like? It might help get my question across better. I’m available for that if required.

  • David
Biopic_100x100_pragsmall
06 Jan 2010, 11:22
Bill Dudney (917 posts)

Hi David,

Sorry this is confusing.

The title property is never discussed beyond its introduction. All the lessons applied to the grossSales property should be brought back to title.

So it remains assign simply because we did not go back and update it in the screencast. It does not present a problem because the autorelease pool does not release it until the end of the program.

When title was introduced we had not dealt with memory mgt so I used assign because its the easiest to understand.

Good luck!

Generic-user-small
07 Jan 2010, 05:01
David Wilson (11 posts)

The title property is never discussed beyond its introduction. All the lessons applied to the grossSales property should be brought back to title.

Excellent. Thank you. All clear now and I understand this within the context of it being a presented and developed example.

I’d love to see a future screencast that does a “deep dive” as such on the @property and the various combinations that can be used there. I believe I “get away with stuff” without having a good understanding of when I should use things like assign, copy, retain etc. I’ve also seen IBOutlet used in the @property line as well as in the declaration area above… lots of combinations.

Anyway.. great screencast series… I’ve got the iPhone book, have had it from the very early beta stage…. and I do refer to it on core topics. The UITableView section has been a great help.

  • David
You must be logged in to comment