Memory Management & Access Control Flashcards

1
Q

TF: All memory management only applies to reference types

A

True, cannot use for value types like structs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Deinit is used for what?

A

to break the class down or deallocate the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

IB outlets are what kind of reference by default?

A

Weak

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
We have the protocol below and we want the customer class to inherit it. Why do we have to put the class in the protocol? 
protocol Loan: class {
    var payee: Customer { get set }
}
class Customer {
    weak var loan: Loan?
}
A

we have to put class in Loan protocol because we have to use reference types when working with weak references

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

TF: Swift makes use of Manual Retain Release.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Assume you created a custom class with a stored property. By default, references to that property will be:

A

Strong

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TF: Strong retain cycles used to be very common before ARC, nowadays, it is nearly impossible to accidentally create one in Swift.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When we talk about allocating memory on a mobile device, we are talking about:

A

RAM

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In Swift, if you find that you have created a strong reference cycle, how should you fix it?

A

Change one of the strong references to weak, using the weak keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the five levels we can restrict our code to?

A
Open 
Public
Internal 
Fileprivate 
Private
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
The member of the class are what by default?
private class SomeClass {}
A

All members of this class are private

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What access level is enabled by default?

A

Internal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

TF: Internal access enables entities to be used within any source file from their defining module and in any source file outside of the module.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

TF: A Swift source file exists within a module

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do we know what level a member of a class can be depending on the class itself?

A

A member can be anything lower than the type of the class itself.

So if a class is private, all members have to be private.

If a class is internal, all members can be fileprivate or private.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly