Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Blog Reader iPhone App Data Modeling Creating a Custom Class: Part 2

Yang Bo
PLUS
Yang Bo
Courses Plus Student 8,503 Points

How to use Weak or Strong

what's mean Parent-Child relation? Is it for classes relation? for example, if Post has many Reply, so post_id, post_name should be strong in Post, post_id should be weak in Reply. right?

4 Answers

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Yang,

yes you're right in as a parent-child relation between instances of objects is meant when trying to avoid a Retain Cycle. A Retain Cycle is the condition when two objects keep a reference to each other and are retained as this creates a retain cycle since both objects try to retain each other, making it impossible to release. You'll have to choose one of the both references and make it a weak pointer (a child so to speak).

... and of course welcome to Treehouse, Yang Bo !

Kind Regards Holger

Yang Bo
Yang Bo
Courses Plus Student 8,503 Points

Wow, thank you so much! Holger Liesegang your answer is very helpful and detail. So can I thought it because child is weak pointer to parent, in this way, it is possible to recycle child firstly, and then it is possible to recycling parent after recycled child(parent is't any reference).

Holger Liesegang
Holger Liesegang
50,595 Points

Yes, exactly - you could think of this like that :) - so if the child has a retain count (ARC) of 0 it will be destroyed (and that will be the case when the last parent - with it's strong pointer to this child - doesn't exist any more). A weak pointer doesn't add to Reference Count.

Holger Liesegang
Holger Liesegang
50,595 Points

...editing posts doesn't work as it is supposed to work at the moment...