首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“`initWithNibName`”上的内存泄漏

“`initWithNibName`”上的内存泄漏
EN

Stack Overflow用户
提问于 2018-10-23 14:05:52
回答 1查看 72关注 0票数 0

我有个记忆泄露的问题。在“仪器”中,我发现了这一行的内存泄漏:

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

我不知道这会有什么问题。以下是VDLPlaybackViewController.h的头文件

代码语言:javascript
复制
@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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-23 15:24:07

插装工具告诉您,下面一行有漏洞:

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

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

您应该查找传递了对VDLPlaybackViewController *videoController的强引用的实例。可以是委托,也可以是完成块。

你在这个问题上的界面有一个小问题。它应该是弱的而不是强的。

代码语言:javascript
复制
@property (nonatomic, weak) id<VDLPlaybackViewControllerDelegate> delegate;

找到更多这样的实例,您已经将VDLPlaybackViewController作为一个强大的引用委托传递给了它,您将能够解决这个问题。

更多地了解泄漏发生的原因。通过https://cocoacasts.com/what-are-strong-reference-cycles

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52951086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档