简体   繁体   中英

IBOutlets and memory management

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM