我有个记忆泄露的问题。在“仪器”中,我发现了这一行的内存泄漏:
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有人知道是什么原因造成的吗?
发布于 2018-10-23 15:24:07
插装工具告诉您,下面一行有漏洞:
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
https://stackoverflow.com/questions/52951086
复制相似问题