Hi all. I'm having trouble understanding this lecture and it was quite confusing to me so I did some additional searching and tried to create a "documentation" by adding comments so that I can understand things better. I'm not sure if my understanding is now completely correct which is why I was hoping that someone could help validate if my understanding is in line with what Paul is trying to convey.
Note: ARC is also new to me and I don't know it that well yet but from my understanding, it just cleans up the memory in Swift (don't know why or how; Don't know what this achieves but I'm guessing it's just to make our code run faster?)
Apologies for the huge block of comments but I hope someone could help validate my understanding and correct me if my understanding of the lecture was wrong.
ARC's an approach to automating when memory is released. Basically, whenever you refer to a variable in a new place, it increases the number of times it's been seen by 1. Then, if that place that called it, it's memory is released, the count goes down by 1. If the count goes to zero, then it can free the variable because nothing is relying on it being there.
There are more wrinkles than that, but that's the most basic explanation. Essentially, it eliminates crashes caused by oddball errors where things got deleted that shouldn't have.
Your summary of the four kinds is correct, but struct isn't quite correct:
This ultimately gets down to whether the memory is allocated on the stack (struct, enum) or heap (class, closure). Stack is faster, but heap is more flexible.
I really like the explanation from the very odd book _Why's Poignant Guide to Ruby:
So if you think of one class/struct instance as one house on a block, and another instance as a different house on the block, the lesson may be clearer.
Does that help at all?
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.