gpt4 book ai didi

ios - `initWithNibName` 内存泄漏

转载 作者:行者123 更新时间:2023-11-28 23:44:06 36 4
gpt4 key购买 nike

我遇到内存泄漏问题。在 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 的强引用的实例。可能作为委托(delegate)或在完成 block 中。

您在问题中使用的界面有一点问题。应该是弱而不是强

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

找到更多这样的实例,在这些实例中,您将 VDLPlaybackViewController 作为强引用委托(delegate)传递,您将能够解决问题。

了解更多关于泄漏实际发生的原因。经过 https://cocoacasts.com/what-are-strong-reference-cycles

关于ios - `initWithNibName` 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52951086/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com