0

I know this could be a duplicated question, but also there are conflicting answers about it ! I'm little confused about that.. my problem is when I profile my app using the instruments to check the leaks .. its keep showing a leak at this method loadNibNamed: .. so related to these questions :

1.Do I need to release IBOutlets when using loadNibNamed: method?

2.Using loadNibNamed leaves a memory leak

I found that some people said that you have to release the IBOutlets even if you don't implement the accessor methods ! and the others says that you shouldn't release these outlets since the iOS will take care about it , so please I need a correct answer based on professoinal experience since that will need me to do alot of work with my project.

Edit / For Example :

If this is my .h class file

@interface MenuViewEPub : UIViewController<ePubBrightnessDelegate,FontDelegate,PagesSlidePreviewerDelegate,ePubExpandSearchBarDelegate,EnviromentAudioChooserDelegate,UIPopoverControllerDelegate,WEPopoverControllerDelegate> {

    IBOutlet UIView *upperMenu;
    IBOutlet UIView *lowerMenu;

    IBOutlet ePubBrightnessButton *brightnessButton;
    IBOutlet FontButton *fontButton;

    IBOutlet UIBarButtonItem *backButtonTitle;
    IBOutlet UIBarButtonItem *indexButtonTitle;
    IBOutlet UIBarButtonItem *annotationButtonTitle;
    UIView *readerView;

    IBOutlet ePubExpandSearchBar *searchBar;

    id<MenuViewControllerDelegat>delegate;

    IBOutlet PagesSlidePreviewer *pageSilder;
    IBOutlet UIButton *arEnButton;

    int pageNumber;

    int chapterIndex;
    int chtCount;

    BOOL isLandscape;

    UIPopoverController *lastPopover;
}
@property (nonatomic, assign) id<MenuViewControllerDelegat>delegate;
@property (nonatomic, retain) ePubExpandSearchBar *searchBar;
@property (nonatomic, assign) int chtCount;
@property (nonatomic, assign) int pageNumber;
@property (nonatomic, assign) int chapterIndex;
@property (nonatomic, assign) BOOL isRotate;

- (IBAction)tocButtonPressed:(id)sender;
- (IBAction)AnnotationsPressed:(id)sender;
- (IBAction)BackPressed:(id)sender;
- (IBAction)rtfPressed:(id)sender;
- (IBAction) audioPressed:(UIButton*)sender;
- (IBAction) tipsPressed:(UIButton*)sender;
- (void) showMenuInView :(UIView*) destview;
- (void) createViews;
- (void) hideMenu : (BOOL)animate;
- (void) changePageNumber:(int)pageNum;

@end

Do I have to release any outlet except the searchBar ?

Community
  • 1
  • 1
Malek_Jundi
  • 6,140
  • 2
  • 27
  • 36

1 Answers1

1

Unless you are using ARC, you should release any retained subviews in the viewDidUnload method. This would include subviews that are "injected" via IBOutlets. You would usually also include anything you might have created yourself in the viewDidLoad method.

Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
  • please @Eric Check my edit. and explain your answer more if this is possible. Thanks. – Malek_Jundi Apr 24 '12 at 15:01
  • @Malek - You would certainly have to release the search bar, but all the other IBOutlets don't have properties that retain them, so theoretically they don't need to be released. However, if you don't retain them, I think you might risk an app crash if they are destroyed unexpectedly. – Eric Petroelje Apr 24 '12 at 15:04
  • why it would crash ? I read that the UIKit is retain all the nib file objects when load it ? is this is incorrect ?! – Malek_Jundi Apr 24 '12 at 15:11
  • @Malek - that's true on the Mac, but not iOS. See here: http://stackoverflow.com/questions/5232973/ios-what-is-best-way-to-manage-memory-for-iboutlets – Eric Petroelje Apr 24 '12 at 15:13