VDLPlaybackViewController

VDLPlaybackViewController

我的内存泄漏有问题。在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


有谁知道是什么原因造成的?

最佳答案

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

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

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

您应该查找传递了对VDLPlaybackViewController *videoController的强引用的实例..可能是作为委托或在完成块中。

您在问题中拥有的接口有一个小问题。应该是弱而不是强

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


找到更多类似的实例,您已经在VDLPlaybackViewController中作为强大的引用委托传递了,您将能够解决问题。

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

08-05 23:28