#461
Up+18/-18DownSeptember 16 2011 at 11:39:16 pm EDT
Старла Эппрект: Mebbe I can explain simply what reference counting is Drifty: harpischords are awesome Drifty: You do that and I'll try to understand Drifty: Teach me, oh grasshopper Старла Эппрект: Okay, so, when you make a new object, it's all "Yay! I'm a new object! I exist!", right? Старла Эппрект: Every object in Objective-C has this counter called a "retain count", and when you make a new object, it's set to 1. Drifty: So objects refer to themselves Старла Эппрект: When another object wants to use that object, it sends that object a retain message, which basically says "Dude, I'm going to totally use you, so please don't spontaneously combust when I'm using you" Drifty: lolol Старла Эппрект: what that retain message really does is increment that counter, so if it starts at 1, it goes to 2 Drifty: Why? Старла Эппрект: When an object is done with the other object (a.k.a. "Let's switch whores!"), it sends it a release message, which decrements the counter (so from 2 to 1) Старла Эппрект: I'm getting to why Drifty: oh god whores what Старла Эппрект: When that counter gets down to 0, the object is destroyed in a fiery explosion, but it's like it's finally at rest Drifty: So the number is like stages of life? Drifty: 0 is dead, 1 is resting, 2 is being used Старла Эппрект: Sort of, it's basically like a tether to life Drifty: why does it go to 0? Старла Эппрект: Well, yeah, but the number can be higher than 2 Drifty: Does another object kill it? Старла Эппрект: If a ton of objects are using it, you can have a retain count of like 17  Старла Эппрект: It goes to 0 when it gets enough release messages, which you're supposed to do after you're done with the object Старла Эппрект: So you're like "this toy is so last year, I'm getting rid of it" Drifty: lol Старла Эппрект: Say there's a bunch of people who all like this book and want to share it, so they all retain it Старла Эппрект: And as they each one by one get sick of it, they each release it Старла Эппрект: The book will continue to exist until every one of those people gets sick of the book and releases it, at which point it has no reason to live so it's like baibai Старла Эппрект: of course, it's a book, so it's not doing that much living anymore anyway Drifty: but it's a living book!