- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我是新手,我可能做错了很多事情,因此,我真的需要你的专业知识和帮助!
我正在创建一个使用 AVFoundation 框架的音乐应用程序。当我在我的 Macbook 和 iOS 设备上测试它时,它实际上在一开始就运行良好。但是在我随机按下 50-100 次不同的音频播放按钮后,它会随机停止工作。该应用程序不会崩溃,但不会播放任何声音。我真的不明白为什么,请帮助我。
更新(2013 年 6 月 7 日):在这里,现在我弄清楚问题是什么,但我不明白......它在调试器中这样说: shm_open 失败:“AppleAudioQueue.39.189049”(25) flags=0x2 errno=24如果可能,请提供帮助:o!
这是我的代码:
[array1 retain];[array1 retain];[array1 retain];
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:[NSString stringWithFormat:@"%@", [[Scale objectAtIndex:array1.retainCount]description]] ofType:@"mp3" inDirectory:@"Piano"];
NSURL *url = [NSURL fileURLWithPath: path];
player = [[AVAudioPlayer alloc]
initWithContentsOfURL:url error:nil];
[player setNumberOfLoops:0];
[player play];
这个问题的一个潜在原因是因为我正在使用 [array retain/release]
并使用数组 retainCount
来引用许多不同的对象。这会导致内存泄漏或类似问题吗?
您好 bbum,感谢您的帮助。供您引用,这是我愚蠢的代码的一部分..我知道这有点乱,如果您需要我的解释或更多详细信息,请告诉我:
- (IBAction)P1C:(id)sender{
KeyCountA1 = [NSMutableArray arrayWithObjects:@"1",@"3",@"5",@"8",@"10",@"12",@"15",@"17",@"19",@"22",@"24",@"26",@"29",@"31",@"33",@"36",@"38",@"40",@"43",@"45",@"47",@"50",@"52",nil];
KeyCountA2 = [NSMutableArray arrayWithObjects:@"0",@"2",@"4",@"6",@"9",@"11",@"13",@"16",@"18",@"20",@"23",@"25",@"27",@"30",@"32",@"34",@"37",@"39",@"41",@"44",@"46",@"48",@"51",nil];
KeyCountA3 = [NSMutableArray arrayWithObjects:@"0",@"3",@"5",@"7",@"10",@"12",@"14",@"17",@"19",@"21",@"24",@"26",@"28",@"31",@"33",@"35",@"38",@"40",@"42",@"45",@"47",@"49",@"52",nil];
KeyCountA4 = [NSMutableArray arrayWithObjects:@"1",@"4",@"6",@"8",@"11",@"13",@"15",@"18",@"20",@"22",@"25",@"27",@"29",@"32",@"34",@"36",@"39",@"41",@"43",@"46",@"48",@"50",nil];
KeyCountA5 = [NSMutableArray arrayWithObjects:@"2",@"5",@"7",@"9",@"12",@"14",@"16",@"19",@"21",@"23",@"26",@"28",@"30",@"33",@"35",@"37",@"40",@"42",@"44",@"47",@"49",@"51",nil];
KeyCountA6 = [NSMutableArray arrayWithObjects:@"1",@"3",@"6",@"8",@"10",@"13",@"15",@"17",@"20",@"22",@"24",@"27",@"29",@"31",@"34",@"36",@"38",@"41",@"43",@"45",@"48",@"50",@"52",nil];
KeyCountA7 = [NSMutableArray arrayWithObjects:@"2",@"4",@"7",@"9",@"11",@"14",@"16",@"18",@"21",@"23",@"25",@"28",@"30",@"32",@"35",@"37",@"39",@"42",@"44",@"46",@"49",@"51",nil];
KeyCountC1 = [NSMutableArray arrayWithObjects:@"1",@"8",@"15",@"22",@"29",@"36",@"43",@"50",nil];
KeyCountC2 = [NSMutableArray arrayWithObjects:@"2",@"9",@"16",@"23",@"30",@"37",@"44",@"51",nil];
KeyCountC3 = [NSMutableArray arrayWithObjects:@"3",@"10",@"17",@"24",@"31",@"38",@"45",@"52",nil];
KeyCountC4 = [NSMutableArray arrayWithObjects:@"4",@"11",@"18",@"25",@"32",@"39",@"46",nil];
KeyCountC5 = [NSMutableArray arrayWithObjects:@"5",@"12",@"19",@"26",@"33",@"40",@"47",nil];
KeyCountC6 = [NSMutableArray arrayWithObjects:@"6",@"13",@"20",@"27",@"34",@"41",@"48",nil];
KeyCountC7 = [NSMutableArray arrayWithObjects:@"7",@"14",@"21",@"28",@"35",@"42",@"49",nil];
//(16-May-2013) Refering to SA&CC and use the right scles play different chords for progression (refer to
//(22-May-2013) adding scales (13-120)
if ((((ScaleArray.retainCount==1)||(ScaleArray.retainCount==2)||(ScaleArray.retainCount==14)||(ScaleArray.retainCount==25)||(ScaleArray.retainCount==26)||(ScaleArray.retainCount==38)||(ScaleArray.retainCount==49)||(ScaleArray.retainCount==50)||(ScaleArray.retainCount==62)||(ScaleArray.retainCount==73)||(ScaleArray.retainCount==74)||(ScaleArray.retainCount==85)||(ScaleArray.retainCount==86)||(ScaleArray.retainCount==98)||(ScaleArray.retainCount==110)||(ScaleArray.retainCount==111))&&(ChordCount.retainCount==1))||
(((ScaleArray.retainCount==3)||(ScaleArray.retainCount==4)||(ScaleArray.retainCount==15)||(ScaleArray.retainCount==16)||(ScaleArray.retainCount==27)||(ScaleArray.retainCount==28)||(ScaleArray.retainCount==39)||(ScaleArray.retainCount==40)||(ScaleArray.retainCount==51)||(ScaleArray.retainCount==52)||(ScaleArray.retainCount==63)||(ScaleArray.retainCount==64)||(ScaleArray.retainCount==75)||(ScaleArray.retainCount==76)||(ScaleArray.retainCount==87)||(ScaleArray.retainCount==88)||(ScaleArray.retainCount==99)||(ScaleArray.retainCount==100)||(ScaleArray.retainCount==112))&&(ChordCount.retainCount==7))||
(((ScaleArray.retainCount==5)||(ScaleArray.retainCount==17)||(ScaleArray.retainCount==18)||(ScaleArray.retainCount==29)||(ScaleArray.retainCount==30)||(ScaleArray.retainCount==41)||(ScaleArray.retainCount==42)||(ScaleArray.retainCount==53)||(ScaleArray.retainCount==54)||(ScaleArray.retainCount==65)||(ScaleArray.retainCount==66)||(ScaleArray.retainCount==77)||(ScaleArray.retainCount==89)||(ScaleArray.retainCount==101)||(ScaleArray.retainCount==102)||(ScaleArray.retainCount==113)||(ScaleArray.retainCount==114))&&(ChordCount.retainCount==6))||
(((ScaleArray.retainCount==6)||(ScaleArray.retainCount==7)||(ScaleArray.retainCount==19)||(ScaleArray.retainCount==31)||(ScaleArray.retainCount==43)||(ScaleArray.retainCount==55)||(ScaleArray.retainCount==67)||(ScaleArray.retainCount==68)||(ScaleArray.retainCount==78)||(ScaleArray.retainCount==79)||(ScaleArray.retainCount==90)||(ScaleArray.retainCount==91)||(ScaleArray.retainCount==103)||(ScaleArray.retainCount==115)||(ScaleArray.retainCount==116))&&(ChordCount.retainCount==5))||
(((ScaleArray.retainCount==8)||(ScaleArray.retainCount==9)||
(ScaleArray.retainCount==20)||(ScaleArray.retainCount==21)||(ScaleArray.retainCount==32)||(ScaleArray.retainCount==33)||(ScaleArray.retainCount==44)||(ScaleArray.retainCount==45)||(ScaleArray.retainCount==56)||(ScaleArray.retainCount==57)||(ScaleArray.retainCount==69)||(ScaleArray.retainCount==80)||(ScaleArray.retainCount==81)||(ScaleArray.retainCount==92)||(ScaleArray.retainCount==93)||(ScaleArray.retainCount==104)||(ScaleArray.retainCount==105)||(ScaleArray.retainCount==117))&&(ChordCount.retainCount==4))||
(((ScaleArray.retainCount==10)||(ScaleArray.retainCount==22)||(ScaleArray.retainCount==34)||(ScaleArray.retainCount==46)||(ScaleArray.retainCount==47)||(ScaleArray.retainCount==58)||(ScaleArray.retainCount==59)||(ScaleArray.retainCount==70)||(ScaleArray.retainCount==71)||(ScaleArray.retainCount==82)||(ScaleArray.retainCount==94)||(ScaleArray.retainCount==95)||(ScaleArray.retainCount==106)||(ScaleArray.retainCount==107)||(ScaleArray.retainCount==118)||(ScaleArray.retainCount==119))&&(ChordCount.retainCount==3))||
(((ScaleArray.retainCount==11)||(ScaleArray.retainCount==12)||(ScaleArray.retainCount==13)||(ScaleArray.retainCount==23)||(ScaleArray.retainCount==24)||(ScaleArray.retainCount==35)||(ScaleArray.retainCount==36)||(ScaleArray.retainCount==37)||(ScaleArray.retainCount==48)||(ScaleArray.retainCount==60)||(ScaleArray.retainCount==61)||(ScaleArray.retainCount==72)||(ScaleArray.retainCount==83)||(ScaleArray.retainCount==84)||(ScaleArray.retainCount==96)||(ScaleArray.retainCount==97)||(ScaleArray.retainCount==108)||(ScaleArray.retainCount==109)||(ScaleArray.retainCount==120))&&(ChordCount.retainCount==2))) {
if ([KeyCountA2 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A2
{if(array1.retainCount+1>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];}}
else if ([KeyCountA1 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A1
{if(array1.retainCount+2>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];}}
else if ([KeyCountC7 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
{if(array1.retainCount+3>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];[array1 retain];}}//C7
}//Phase#1
if ((((ScaleArray.retainCount==1)||(ScaleArray.retainCount==2)||(ScaleArray.retainCount==14)||(ScaleArray.retainCount==25)||(ScaleArray.retainCount==26)||(ScaleArray.retainCount==38)||(ScaleArray.retainCount==49)||(ScaleArray.retainCount==50)||(ScaleArray.retainCount==62)||(ScaleArray.retainCount==73)||(ScaleArray.retainCount==74)||(ScaleArray.retainCount==85)||(ScaleArray.retainCount==86)||(ScaleArray.retainCount==98)||(ScaleArray.retainCount==110)||(ScaleArray.retainCount==111))&&(ChordCount.retainCount==2))||
(((ScaleArray.retainCount==3)||(ScaleArray.retainCount==4)||(ScaleArray.retainCount==15)||(ScaleArray.retainCount==16)||(ScaleArray.retainCount==27)||(ScaleArray.retainCount==28)||(ScaleArray.retainCount==39)||(ScaleArray.retainCount==40)||(ScaleArray.retainCount==51)||(ScaleArray.retainCount==52)||(ScaleArray.retainCount==63)||(ScaleArray.retainCount==64)||(ScaleArray.retainCount==75)||(ScaleArray.retainCount==76)||(ScaleArray.retainCount==87)||(ScaleArray.retainCount==88)||(ScaleArray.retainCount==99)||(ScaleArray.retainCount==100)||(ScaleArray.retainCount==112))&&(ChordCount.retainCount==1))||
(((ScaleArray.retainCount==5)||(ScaleArray.retainCount==17)||(ScaleArray.retainCount==18)||(ScaleArray.retainCount==29)||(ScaleArray.retainCount==30)||(ScaleArray.retainCount==41)||(ScaleArray.retainCount==42)||(ScaleArray.retainCount==53)||(ScaleArray.retainCount==54)||(ScaleArray.retainCount==65)||(ScaleArray.retainCount==66)||(ScaleArray.retainCount==77)||(ScaleArray.retainCount==89)||(ScaleArray.retainCount==101)||(ScaleArray.retainCount==102)||(ScaleArray.retainCount==113)||(ScaleArray.retainCount==114))&&(ChordCount.retainCount==7))||
(((ScaleArray.retainCount==6)||(ScaleArray.retainCount==7)||(ScaleArray.retainCount==19)||(ScaleArray.retainCount==31)||(ScaleArray.retainCount==43)||(ScaleArray.retainCount==55)||(ScaleArray.retainCount==67)||(ScaleArray.retainCount==68)||(ScaleArray.retainCount==78)||(ScaleArray.retainCount==79)||(ScaleArray.retainCount==90)||(ScaleArray.retainCount==91)||(ScaleArray.retainCount==103)||(ScaleArray.retainCount==115)||(ScaleArray.retainCount==116))&&(ChordCount.retainCount==6))||
(((ScaleArray.retainCount==8)||(ScaleArray.retainCount==9)||(ScaleArray.retainCount==20)||(ScaleArray.retainCount==21)||(ScaleArray.retainCount==32)||(ScaleArray.retainCount==33)||(ScaleArray.retainCount==44)||(ScaleArray.retainCount==45)||(ScaleArray.retainCount==56)||(ScaleArray.retainCount==57)||(ScaleArray.retainCount==69)||(ScaleArray.retainCount==80)||(ScaleArray.retainCount==81)||(ScaleArray.retainCount==92)||(ScaleArray.retainCount==93)||(ScaleArray.retainCount==104)||(ScaleArray.retainCount==105)||(ScaleArray.retainCount==117))&&(ChordCount.retainCount==5))||
(((ScaleArray.retainCount==10)||(ScaleArray.retainCount==22)||(ScaleArray.retainCount==34)||(ScaleArray.retainCount==46)||(ScaleArray.retainCount==47)||(ScaleArray.retainCount==58)||(ScaleArray.retainCount==59)||(ScaleArray.retainCount==70)||(ScaleArray.retainCount==71)||(ScaleArray.retainCount==82)||(ScaleArray.retainCount==94)||(ScaleArray.retainCount==95)||(ScaleArray.retainCount==106)||(ScaleArray.retainCount==107)||(ScaleArray.retainCount==118)||(ScaleArray.retainCount==119))&&(ChordCount.retainCount==4))||
(((ScaleArray.retainCount==11)||(ScaleArray.retainCount==12)||(ScaleArray.retainCount==13)||(ScaleArray.retainCount==23)||(ScaleArray.retainCount==24)||(ScaleArray.retainCount==35)||(ScaleArray.retainCount==36)||(ScaleArray.retainCount==37)||(ScaleArray.retainCount==48)||(ScaleArray.retainCount==60)||(ScaleArray.retainCount==61)||(ScaleArray.retainCount==72)||(ScaleArray.retainCount==83)||(ScaleArray.retainCount==84)||(ScaleArray.retainCount==96)||(ScaleArray.retainCount==97)||(ScaleArray.retainCount==108)||(ScaleArray.retainCount==109)||(ScaleArray.retainCount==120))&&(ChordCount.retainCount==3))) {
if ([KeyCountA3 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
{if(array1.retainCount+1>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];}}
else if ([KeyCountA2 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])//A1
{if(array1.retainCount+2>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];}}
else if ([KeyCountC1 containsObject:[NSString stringWithFormat:@"%d",array1.retainCount]])
{if(array1.retainCount+3>Max){[S1S sendActionsForControlEvents:UIControlEventTouchDown];}else{[array1 retain];[array1 retain];[array1 retain];}}//C7
}//Phase#2
//跳过阶段#3-7
[ChangeScale sendActionsForControlEvents:UIControlEventTouchUpInside];
[label1 setText:[NSString stringWithFormat:@"%d = %@", array1.retainCount, [[KeyName objectAtIndex:array1.retainCount]description]]];
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:[NSString stringWithFormat:@"%@",[[Scale objectAtIndex:array1.retainCount]description]]
ofType:@"mp3"
inDirectory:@"Piano"];
NSURL *url = [NSURL fileURLWithPath: path];
player = [[AVAudioPlayer alloc]
initWithContentsOfURL:url error:nil];
[player setNumberOfLoops:0];
[player play];
[EnableButton sendActionsForControlEvents:UIControlEventTouchUpInside];
[CCC sendActionsForControlEvents:UIControlEventTouchUpInside];
[EDCButtons sendActionsForControlEvents:UIControlEventTouchUpInside];
*note: "Scale" and "KeyName" are arrays** enabled differently according to ScaleArray.retainCount.
最佳答案
除了说明您确实需要重新访问 basics of memory management 之外,没有足够的代码说明可能发生的情况。 .
连续三个retain
?没有意义,表示猜测正在发生的事情。
retainCount
没用;别叫它。 http://www.whentouseretaincount.com/
您是否尝试过在您的代码上运行静态分析器?
From your comment I can tell I am really doing everything wrong. In my code, I am using different retainCount number to represent different keys on the piano keyboard... Because I don't know how to use a int or a integer value that run across all my IBAction
我很抱歉——我不是故意这么严厉!
我们都曾经犯过错。使用 retainCount
来存储 UI 状态实际上是我所见过的对该 API 最有创意的滥用之一!所以,不,你绝对不是傻,只是走错了路!
听起来您需要退后一步,看看应用程序是如何组合在一起的。在这种情况下,您有 N 个单独的按钮,每个按钮都会触发几乎相同的操作。因此,您需要将一些数据附加到这些按钮。
如果按钮是在 Interface Builder 中创建的,您可以为每个按钮分配一个标签。如果它们是以编程方式创建的,您也可以这样做。 NSButton 和 UIButton 都有标签,因此您可以在两个平台上使用相同的解决方案。
如果不进一步了解按钮的实现方式,就很难说得更具体。
关于ios - 经常使用 AVAudioPlayer 后突然没有声音 -- 请帮助 ["AppleAudioQueue.39.189049"(25) flags=0x2 errno=24],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16833518/
问题故障解决记录 -- Java RMI Connection refused to host: x.x.x.x .... 在学习JavaRMI时,我遇到了以下情况 问题原因:可
我正在玩 Rank-N-type 并尝试输入 x x .但我发现这两个函数可以以相同的方式输入,这很不直观。 f :: (forall a b. a -> b) -> c f x = x x g ::
这个问题已经有答案了: How do you compare two version Strings in Java? (31 个回答) 已关闭 8 年前。 有谁知道如何在Java中比较两个版本字符串
这个问题已经有答案了: How do the post increment (i++) and pre increment (++i) operators work in Java? (14 个回答)
下面是带有 -n 和 -r 选项的 netstat 命令的输出,其中目标字段显示压缩地址 (127.1/16)。我想知道 netstat 命令是否有任何方法或选项可以显示整个目标 IP (127.1.
我知道要证明 : (¬ ∀ x, p x) → (∃ x, ¬ p x) 证明是: theorem : (¬ ∀ x, p x) → (∃ x, ¬ p x) := begin intro n
x * x 如何通过将其存储在“auto 变量”中来更改?我认为它应该仍然是相同的,并且我的测试表明类型、大小和值显然都是相同的。 但即使 x * x == (xx = x * x) 也是错误的。什么
假设,我们这样表达: someIQueryable.Where(x => x.SomeBoolProperty) someIQueryable.Where(x => !x.SomeBoolProper
我有一个字符串 1234X5678 我使用这个正则表达式来匹配模式 .X|..X|X. 我得到了 34X 问题是为什么我没有得到 4X 或 X5? 为什么正则表达式选择执行第二种模式? 最佳答案 这里
我的一个 friend 在面试时遇到了这个问题 找到使该函数返回真值的 x 值 function f(x) { return (x++ !== x) && (x++ === x); } 面试官
这个问题在这里已经有了答案: 10年前关闭。 Possible Duplicate: Isn't it easier to work with foo when it is represented b
我是 android 的新手,我一直在练习开发一个针对 2.2 版本的应用程序,我需要帮助了解如何将我的应用程序扩展到其他版本,即 1.x、2.3.x、3 .x 和 4.x.x,以及一些针对屏幕分辨率
为什么案例 1 给我们 :error: TypeError: x is undefined on line... //case 1 var x; x.push(x); console.log(x);
代码优先: # CASE 01 def test1(x): x += x print x l = [100] test1(l) print l CASE01 输出: [100, 100
我正在努力温习我的大计算。如果我有将所有项目移至 'i' 2 个空格右侧的函数,我有一个如下所示的公式: (n -1) + (n - 2) + (n - 3) ... (n - n) 第一次迭代我必须
给定 IP 字符串(如 x.x.x.x/x),我如何或将如何计算 IP 的范围最常见的情况可能是 198.162.1.1/24但可以是任何东西,因为法律允许的任何东西。 我要带198.162.1.1/
在我作为初学者努力编写干净的 Javascript 代码时,我最近阅读了 this article当我偶然发现这一段时,关于 JavaScript 中的命名空间: The code at the ve
我正在编写一个脚本,我希望避免污染 DOM 的其余部分,它将是一个用于收集一些基本访问者分析数据的第 3 方脚本。 我通常使用以下内容创建一个伪“命名空间”: var x = x || {}; 我正在
我尝试运行我的test_container_services.py套件,但遇到了以下问题: docker.errors.APIError:500服务器错误:内部服务器错误(“ b'{” message
是否存在这两个 if 语句会产生不同结果的情况? if(x as X != null) { // Do something } if(x is X) { // Do something } 编
我是一名优秀的程序员,十分优秀!