首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS- -如何修复XCode中来自情态符号的保留周期?

iOS- -如何修复XCode中来自情态符号的保留周期?
EN

Stack Overflow用户
提问于 2016-05-16 18:42:02
回答 1查看 457关注 0票数 0

我运行分配工具,我肯定有一个保留周期,楼梯状的图形是一个死的赠品。然而,我对iOS编程并不熟悉,甚至在筛选完互联网上的文档之后,我也不知道如何解决我的保留周期问题。据我所知,有一些强有力的引用正在阻止未使用的内存在我的ARC项目中被释放。这个应用程序是一个简单的声音板,但有很多内容,这就是为什么我从来没有处理过这个问题。记忆现在是一个真正的问题。对于ViewController.m我有

代码语言:javascript
复制
@import GoogleMobileAds;

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController () <GADInterstitialDelegate, UIAlertViewDelegate>
{
    AVAudioPlayer *_audioPlayer;
}
@property(nonatomic, strong) GADInterstitial *interstitial;

@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createAndLoadInterstitial];

    BannerManager *sharedManager = [BannerManager sharedManager];
    GADBannerView* bView = [sharedManager setupBannerAds:self.view];
    bView.delegate = self;
    bView.rootViewController = self;

    GADRequest *request = [GADRequest request];
    [bView loadRequest:request];
}

- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
    NSLog(@"adViewDidReceiveAd: %@", bannerView.adNetworkClassName);
}


int counter = 0;

#pragma Interstitial button actions

- (IBAction)playAgain:(id)sender {

    if (counter % 15 == 0) {
        if (self.interstitial.isReady) {
            [self.interstitial presentFromRootViewController:self];
        } else {

        }
    }

    counter++;
}

- (void)createAndLoadInterstitial {
    self.interstitial =
    [[GADInterstitial alloc] initWithAdUnitID:@"mygoogleidgoeshere"];
    self.interstitial.delegate = self;

    GADRequest *request = [GADRequest request];

    [self.interstitial loadRequest:request];
}


#pragma mark GADInterstitialDelegate implementation

- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
    NSLog(@"interstitialDidFailToReceiveAdWithError: %@", [error localizedDescription]);
}

- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial {
    NSLog(@"interstitialDidDismissScreen");
    [self createAndLoadInterstitial];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





- (IBAction)areyoufinishedyet:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"areyoufinishedyet"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];

}

- (IBAction)areyoulooking:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"areyoulooking"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)blueeyes:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"blueeyes"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)crosshairs:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"crosshairs"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)doyoumind:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"doyoumind"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)dontblink:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"dontblink"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)growontrees:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"growontrees"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)iamagenius:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"iamagenius"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)imarealboy:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"imarealboy"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)importantbusiness:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"importantbusiness"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)inmyeye:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"inmyeye"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)justblinked:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"justblinked"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)mustyoureally:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"mustyoureally"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)nottheenemy:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"nottheenemy"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)oddlyenough:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"oddlyenough"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)staringcontest:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"staringcontest"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];
}

- (IBAction)youreaklutz:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"youreaklutz"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)youreamoron:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"youreamoron"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)yourepissingmeoff:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"yourepissingmeoff"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)challengeme:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"challengeme"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

- (IBAction)forerunners:(id)sender {

    soundFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                        pathForResource:@"forerunners"
                                        ofType:@"mp3"]];

    sound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFile error:nil];
    sound.delegate = self;
    [sound play];}

对于视图控制器,我有

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import "BannerManager.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@import GoogleMobileAds;

@interface ViewController: UIViewController<GADBannerViewDelegate, AVAudioPlayerDelegate>  {
    NSURL *soundFile;
    AVAudioPlayer *sound;
}

//343 GUILTY SPARK
- (IBAction)areyoufinishedyet:(id)sender;
- (IBAction)areyoulooking:(id)sender;
- (IBAction)blueeyes:(id)sender;
- (IBAction)crosshairs:(id)sender;
- (IBAction)doyoumind:(id)sender;
- (IBAction)dontblink:(id)sender;
- (IBAction)growontrees:(id)sender;
- (IBAction)iamagenius:(id)sender;
- (IBAction)imarealboy:(id)sender;
- (IBAction)importantbusiness:(id)sender;
- (IBAction)inmyeye:(id)sender;
- (IBAction)justblinked:(id)sender;
- (IBAction)mustyoureally:(id)sender;
- (IBAction)nottheenemy:(id)sender;
- (IBAction)oddlyenough:(id)sender;
- (IBAction)staringcontest:(id)sender;
- (IBAction)youreaklutz:(id)sender;
- (IBAction)youreamoron:(id)sender;
- (IBAction)yourepissingmeoff:(id)sender;

//ARBITER
- (IBAction)challengeme:(id)sender;
- (IBAction)forerunners:(id)sender;
- (IBAction)halospurpose:(id)sender;
- (IBAction)imgoingtocutit:(id)sender;
- (IBAction)imprepared:(id)sender;
- (IBAction)readytofight:(id)sender;
- (IBAction)sacredrings:(id)sender;
- (IBAction)saveyouranger:(id)sender;
- (IBAction)youshotmefoo:(id)sender;
- (IBAction)tararusstop:(id)sender;
- (IBAction)trymypatience:(id)sender;
- (IBAction)whatyouwant:(id)sender;
- (IBAction)arbiterdo:(id)sender;

//BRUTES
- (IBAction)adaysrations:(id)sender;
- (IBAction)atinymorsel:(id)sender;
- (IBAction)bastardelite:(id)sender;
- (IBAction)boilinyourpot:(id)sender;
- (IBAction)cannedmeat:(id)sender;
- (IBAction)cannotescape:(id)sender;

这只是代码的一部分,因为其余的代码非常庞大,基本上是同一行代码一遍又一遍,对它引用的文件做了一些微小的更改。我的问题是,在这个世界上,我如何修正保留周期?这跟我的模态转换有关吗?因为这就是在我的原生iOS设备上造成设备内存分配和崩溃的原因。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-16 19:32:13

在我看来,你似乎没有一个保留的周期。听起来,在其他视图控制器之上,您正在呈现一个无休止的视图控制器系列。

使用模态当前或导航控制器push具有类似的效果:前面的视图控制器会被一个新的视图控制器覆盖,但不会被释放。

您没有发布任何显示如何从视图控制器导航到视图控制器的代码,因此很难确切地知道您在做什么。

如果您想从视图控制器A到视图控制器B到查看控制器C,然后返回到A,则需要从A到B,然后从B到C,但是为了返回而解散,而不是呈现视图控制器A的新副本。

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

https://stackoverflow.com/questions/37260995

复制
相关文章

相似问题

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