small medium large xlarge

28 Feb 2009, 05:05
Jim Zajkowski (1 post)

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?

01 Mar 2009, 16:45
Bill Dudney (916 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