- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我运行了分配工具,我肯定有一个保留周期,阶梯状的图表是一个死的赠品。但是,我是 iOS 编程的新手,甚至在通过互联网筛选文档后也不知道如何解决我的保留周期问题。据我所知,有一些强引用阻止未使用的内存在我的 ARC 项目中被释放。该应用程序是一个简单的音板,但内容很多,这就是为什么我以前不必处理这个问题。内存现在是一个真正的问题。对于 ViewController.m,我有
@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];}
对于 Viewcontroller.h 我有
#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;
这只是代码的一部分,因为其余部分相当庞大,并且基本上是同一行代码,只是对其引用的文件进行了微小的更改。我的问题是我究竟该如何修复保留周期?这与我的模态转换有关吗?因为这就是导致仪器内存分配异常和我的 native iOS 设备崩溃的原因。
最佳答案
在我看来,您确实没有保留周期。听起来您正在其他 View Controller 之上呈现一系列永无止境的 View Controller 。
使用模态呈现或导航 Controller 推送具有类似的效果:先前的 View Controller 被新 View Controller 覆盖但未被释放。
您没有发布任何显示如何从 View Controller 导航到 View Controller 的代码,因此很难说出您到底在做什么。
如果你想从 View Controller A 到 View Controller B 再到 View Controller C,然后返回到 A,你需要从 A 到 B,然后从 B 到 C,但是为了返回而关闭,而不是呈现 View Controller A 的新副本。
关于iOS-如何修复来自 XCode 中模态转场的保留周期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260995/
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我正在尝试将 JSON 发送到我的服务器并作为结果检索 JSON。例如发送用户名和密码并取回 token 和其他内容。 这就是我正在为发送的 HTTP 请求所做的。我现在如何检索同一请求中的内容?
我有以下 xts 矩阵: > options(digits.secs = 6) > set.seed(1234) > xts(1:10, as.POSIXlt(1366039619, tz="EST"
我目前正在开发一个应用程序,当用户到达某个位置时,它会提醒用户。我希望这个应用程序也在后台运行并搜索解决方案。 在 AppStore 中,我发现了一款名为“Sleep Cycle”的应用程序,它可
我想创建一个基于 farbtastic color picker 的颜色选择器。我想要实现的是添加我想要链接到色轮的 RGB slider 。这是我到目前为止所拥有的。 app.controller(
RFC 5545 允许 RDATE 属性具有 PERIOD 数据类型。该数据类型的语义是什么?据我所知,这是未指定的。它会改变事件的持续时间吗?如果时区更改且没有持续时间怎么办? 最佳答案 尽管我
在 CodinGame学习平台,C# 教程中用作示例的问题之一是: The aim of this exercise is to check the presence of a number in a
我听说网上有一本英特尔书,它描述了特定汇编指令所需的 CPU 周期,但我找不到(经过努力)。谁能告诉我如何找到CPU周期? 这是一个例子,在下面的代码中,mov/lock 是 1 个 CPU 周期,x
据我所知,Java GC有次要GC(低成本)和主要GC周期(高成本)。如果对象在本地范围内,则会在 Minor GC 中清理它。如果对象的引用存储在代码中的其他位置,则它会在主 GC 中被清除。 例如
到目前为止,我有一个很好的自旋锁,可以用作 intendend: std::atomic_flag barrier = ATOMIC_FLAG_INIT; inline void lo
晚上好,我将 cycle2 与 prev 和 next 函数一起使用,但我无法将 prev 和 next 函数置于图像下方的中心。我环顾四周,我知道这会很愚蠢,但我就是看不到它。非常令人沮丧。谢谢加里
出于教育目的,我想知道在优化(在不同级别)和编译之后执行函数需要多少 CPU 周期。有没有办法分析代码或可执行文件以获得可重现的答案?我在 64 位 Windows 7 Pro 上使用 Eclipse
我想彻底测量和调整我的 C/C++ 代码,以便在 x86_64 系统上更好地使用缓存。我知道如何使用计数器(我的 Windows 机器上的 QueryPerformanceCounter)来测量时间,
我尝试将一些数据分组到每四周一次的存储桶中,并使用 pd.Grouper(key='created_at', freq='4W')。我希望这些组是这样的,如果我有从 2019-08-26 到 2019
我正在做一个关于随机数的大型学校项目,但我找不到 Math.random() 的句点。我安装了 7.0.800.15 版本,并且正在使用 Windows 10 计算机。我试过用一个简单的程序来确定周期
我正在努力解决我们生产环境中垃圾收集利用率高的问题,我想知道设置一个大的堆大小来保证老年代永远不会被填满是否会阻止触发主要的 GC 周期。 为了实现这一点,我想有一个特定的阈值标记会触发主要的 GC
我想测量在 Python 3 中执行加法运算所需的时钟周期数。 我写了一个程序来计算加法运算的平均值: from timeit import timeit def test(n): for i
我正在寻找一种方法来测量线程上的函数调用所花费的 cpu 周期。 示例伪代码: void HostFunction() { var startTick = CurrentThread.Cur
就 CPU 周期而言,malloc() 的成本是多少?(Vista/OS,最新版本的 gcc,最高优化级别,...) 基本上,我正在实现一个复杂的 DAG 结构(类似于链表)由一些 16B(不太常见)
C/C++ 中的类型转换会导致额外的 CPU 周期吗? 我的理解是,至少在某些情况下应该消耗额外的 CPU 周期。就像从浮点类型转换为整数一样,CPU 需要将浮点结构转换为整数。 float a=2.
我是一名优秀的程序员,十分优秀!