0
0
Swiftprogramming~5 mins

ARC overview for memory management in Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does ARC stand for in Swift?
ARC stands for Automatic Reference Counting. It helps manage memory by keeping track of how many references point to an object.
Click to reveal answer
beginner
How does ARC decide when to free an object?
ARC frees an object when its reference count drops to zero, meaning no part of the code is using it anymore.
Click to reveal answer
beginner
What is a strong reference in ARC?
A strong reference is the default way Swift keeps an object alive by increasing its reference count when assigned.
Click to reveal answer
intermediate
What problem can strong reference cycles cause?
Strong reference cycles happen when two objects hold strong references to each other, preventing ARC from freeing them and causing memory leaks.
Click to reveal answer
intermediate
How can you break a strong reference cycle in Swift?
You can use weak or unowned references to break strong reference cycles. These references do not increase the reference count.
Click to reveal answer
What happens when an object's reference count reaches zero in ARC?
AThe object is deallocated and memory is freed.
BThe object is copied to a new memory location.
CThe object is marked as read-only.
DNothing happens; the object stays in memory.
Which type of reference increases an object's reference count in Swift ARC?
AWeak reference
BUnowned reference
CNone of the above
DStrong reference
What keyword is used in Swift to declare a weak reference?
Aunowned
Bweak
Cstrong
Dvar
Why are strong reference cycles problematic?
AThey prevent ARC from freeing memory, causing leaks.
BThey delete objects too early.
CThey slow down the CPU.
DThey cause the program to crash immediately.
Which reference type should you use when you know the referenced object will always exist during the reference's lifetime?
Astrong
Bweak
Cunowned
Doptional
Explain how ARC manages memory in Swift and what happens when an object's reference count changes.
Think about how Swift keeps track of who is using an object.
You got /3 concepts.
    Describe what a strong reference cycle is and how to prevent it in Swift.
    Consider how two friends holding hands tightly might never let go.
    You got /3 concepts.