1

I have application where I want to show my CustomView (inherited from UIView) with some content. But I don't need it at each point during runtime so I would like to create it and also delete it to avoid wasting with memory.

I have this view in separate nib file. And loading it with this code in viewController:

NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil];

for (id object in arr) {
    if ([object isKindOfClass:[MyCustomView class]])
        self.myCustomView = (MyCustomView *)object;
}  

[self.view addSubview:self.myCustomView];

myCustomView is property of viewController

@property (nonatomic, strong) IBOutlet MyCustomView *myCustomView;

But in Instruments I can see that #Living is 3 (for example, when I call the code above three times), #Transitory is still 1 and #Overall is 4. It means MyCustomView leaks :( When I set self.myCustomView = nil it is useless :(

Could someone please help me to solve this leak? I'm using ARC.

D33
  • 239
  • 1
  • 3
  • 14

1 Answers1

0

I think [MyCustomView removeFromSuperview] will do the job. :)

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Morten Gustafsson
  • 1,869
  • 2
  • 24
  • 34