small medium large xlarge

Generic-user-small
28 Feb 2009, 05:05
Jim Zajkowski (2 posts)

Bill, in episode two you fixed up the setGrossSales: method by adding a release on the old value before retaining the new.

I can imagine a case where setGrossSales: gets called with the current value of grossSales, and that will cause an error, as the object will be deallocated before it can be retained. For example, adding [movie setGrossSales:[movie grossSales]] (after [salesNumber release]) will cause an exception.

Shouldn’t the setGrossSales: either retain before releasing or autorelease the old, to prevent it from being released prematurely?

Biopic_100x100_pragsmall
01 Mar 2009, 16:45
Bill Dudney (917 posts)

Hi Jim,

You are correct. That is why I say latter that you should always use properties because you don’t have to worry with that complexity.

Thanks for letting me know.

You must be logged in to comment