[英]Memory leak on `initWithNibName`
我的內存泄漏有問題。 在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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.