Sobes.tech
Junior — Middle

What memory format is used for storing reference type objects?

sobes.tech AI

Answer from AI

Reference type objects in iOS (such as classes in Swift or Objective-C) are stored in a managed heap. This is a dynamically allocated memory area where objects are created and live as long as there are references to them.

Unlike value types (struct, enum), which are usually stored on the stack or inside other objects, reference type objects are allocated on the heap, and variables contain pointers (references) to these objects.

Example:

class Person {
    var name: String
    init(name: String) {
        self.name = name
    }
}

let person = Person(name: "Ivan") // object is created on the heap

Here, person is a reference to an object on the heap.