23 Preventing Memory Leaks

It is pretty common to have relationships that go in two directions. For example, maybe an asset should know which employee is currently holding it. Let’s add that relationship. The new object diagram would look like this:

Figure 23.1  Adding holder relationship

Adding holder relationship

From a design standpoint, you would say that you are adding a pointer from the child (an instance of BNRAsset) back to its parent (the instance of BNREmployee that is holding it).

In BNRAsset.h, add a pointer instance variable to hold on to the holding employee:

#import <Foundation/Foundation.h>
@class BNREmployee; @interface BNRAsset ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.