About Owning


#1

Hello friends,

First of all I loved this book, this book helps people understand the principles of Obj-C very effectively.

However, there is a sentence on page 127 that I couldn’t really understand:

It says, “The asset owns the employee and the employee owns the assets array, and the assets array owns the asset.”

I can see how assets array owns the asset, but I am having trouble with the first two.

I would be very happy, if someone points where the first two are in the code (by giving page number and line number LOL :unamused: or you could just write that line)

Thanks.


#2

Look at the diagram on Page 125, and follow the arrows with the labels assets and holder and the unlabelled arrows from the NSMutableArray on the right. I am guessing that each of those arrows designate properties that have the strong ownership qualifier set. Therefore “The asset owns the employee and the employee owns…”


#3

This is correct - take a look at the diagram, it illustrates this perfectly.

As it was stated in this chapter - the clid object (asset in this case) should never own it’s parent object (Employee in this case ) hence why you don’t get deallocating messages for the objects with assets - because the asset still has one owner - employee - so it cannot be deallocated.

I hope this clears it up a little.


#4

I am trying to come to terms with this too.

This is correct - take a look at the diagram, it illustrates this perfectly.

As it was stated in this chapter - the clid object (asset in this case) should never own it’s parent object (Employee in this case ) hence why you don’t get deallocating messages for the objects with assets - because the asset still has one owner - employee - so it cannot be deallocated.

I hope this clears it up a little.[/quote]

Both of you make sense. Correct me if im wrong the reason why you are unable to deallocate assets and employees that have assets is because the employees that have assets are owned by their assets and hence they and neither their assets can be deallocated.

I have a question regarding the statement on Page 127. In parenthesis on the first paragraph Aaron talks about one of his favorite bugs. He mentions that the addAssetsObject calls setHolder (which makes sense as we made that change earlier on in the code). I do not understand how setHolder calls addAssetsObject. setHolder is initialized using @property/synthesize commands. If i had used a method that sets a pointer to the parents collection using the addAssetsObject method (as shown on page 126) then sure i can see how it could be an infinite loop. but we didn’t use that option.

Thank you in advance :slight_smile: