3

I have an issue with this code in iOS9, this codes causes a memory leak each time it is called. I found this leak in instruments and the iOS function that seems to be leaking is [UITabBarButton initWithImage:selectedImage:label:withInsets:].

    UITabBarItem *item0 = [tabBarLibrary.items objectAtIndex:0];
    item0.image = [UIImage imageNamed:@"TabBarIcon1.png"];

Anyone else have this issue or have a way to work around it? Basically the code is switching the icon for the tab bar depending on the situation nothing complicated.

Matthew
  • 161
  • 9

1 Answers1

0

I set any existing image to nil before setting the new one.

UITabBarItem *item0 = [tabBarLibrary.items objectAtIndex:0];
item0.image = nil;
item0.image = [UIImage imageNamed:@"TabBarIcon1.png"];

This enables ARC to free up memory used by any existing image.

Carl
  • 2,896
  • 2
  • 32
  • 50