initWithNibName上的内存泄漏

时间:2018-10-23 14:05:52

标签: ios uiviewcontroller

我遇到内存泄漏问题。在Instruments中,此行出现内存泄漏:

VDLPlaybackViewController *videoController = [[VDLPlaybackViewController alloc] initWithNibName:@"VDLPlaybackView" bundle:nil];

我不确定这可能是什么问题。这是VDLPlaybackViewController.h的头文件:

@protocol VDLPlaybackViewControllerDelegate <NSObject>
@required
-(void)playerShouldClose;
@end

@interface VDLPlaybackViewController : UIViewController <UIDocumentInteractionControllerDelegate>


@property (nonatomic, strong) id<VDLPlaybackViewControllerDelegate> delegate;

// content file stuff.
@property (nonatomic, strong) File *file;
@property (nonatomic, strong) NSNumber *contentID;
@property (nonatomic, strong) NSURL *fileURL;
@property (nonatomic, strong) NSString *pageTitle;

// layout stuff
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topTimeViewHeight;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomControlViewHeight;

@property (nonatomic, strong) IBOutlet UIView *movieView;
@property (nonatomic, strong) IBOutlet UIView *navBarView;
@property (nonatomic, strong) IBOutlet UISlider *positionSlider;
@property (nonatomic, strong) IBOutlet UIButton *timeDisplay;
@property (nonatomic, strong) IBOutlet UIButton *playPauseButton;
@property (nonatomic, strong) IBOutlet UIButton *subtitleSwitcherButton;
@property (nonatomic, strong) IBOutlet UIButton *audioSwitcherButton;
@property (nonatomic, strong) IBOutlet UIButton *screenSizeSwitcherButton;
//@property (nonatomic, strong) IBOutlet UINavigationBar *toolbar;
@property (nonatomic, strong) IBOutlet UIView *controllerPanel;
@property (nonatomic, strong) IBOutlet UISlider *volumeSlider;
@property (nonatomic, strong) IBOutlet MPVolumeView *volumeView;
@property (nonatomic, strong) IBOutlet MPVolumeView *airplayView;

@property (nonatomic, assign) CGRect shareButtonFrame;
@property (nonatomic, strong) MultiFileShareButtonController *shareButtonController;
@property (nonatomic, strong) FavoriteFileButtonView *favoriteButtonController;
@property (nonatomic, strong) UIDocumentInteractionController *interactionController;
@property (nonatomic, assign) BOOL isDestroying;

- (void)setMediaURL:(NSURL*)theURL;

- (IBAction)closePlayback:(id)sender;

- (IBAction)positionSliderDrag:(id)sender;
- (IBAction)positionSliderAction:(id)sender;
- (IBAction)toggleTimeDisplay:(id)sender;

- (IBAction)playandPause:(id)sender;
//- (IBAction)switchAudioTrack:(id)sender;
//- (IBAction)switchSubtitleTrack:(id)sender;
- (IBAction)switchVideoDimensions:(id)sender;

@end

有人知道是什么原因吗?

1 个答案:

答案 0 :(得分:1)

检测工具告诉您以下行存在泄漏:

Elevator

这并不意味着是导致泄漏的仅此行,该工具告诉您该变量的引用作为泄漏存在。

您应该查找传递了对VDLPlaybackViewController *videoController = [[VDLPlaybackViewController alloc] initWithNibName:@"VDLPlaybackView" bundle:nil];的强引用的实例。

您在问题中遇到的界面有一些问题。应该是弱而不是强

VDLPlaybackViewController *videoController

找到更多类似的实例,您已经在@property (nonatomic, weak) id<VDLPlaybackViewControllerDelegate> delegate; 中作为强大的参考委托人来回去,您将能够解决问题。

进一步了解泄漏实际发生的原因。经过 https://cocoacasts.com/what-are-strong-reference-cycles