Value objects and reference objects
In the previous chapter, you learned the benefits of using immutable value objects. Value objects not only make code safer and clearer, they also make it faster. Value objects have better speed performance than reference objects and here is why. As an example of a value object, we will use structures in this chapter.
Memory allocation
Value objects can be allocated on the stack memory instead of the heap memory. Reference objects need to be allocated on the heap memory because they can be shared between many owners. Because value objects have only one owner they can be safely allocated on the stack. Stack memory is way faster that heap memory.
The second advantage is that value objects don't need reference counting memory management. As they can have only one owner, there is no such thing as reference counting for value objects. With ARC (Automatic Reference Counting), we don't need to think so much about memory management and it mostly looks transparent...