首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未能分配OutOfMemoryError

未能分配OutOfMemoryError
EN

Stack Overflow用户
提问于 2020-10-10 10:50:51
回答 1查看 278关注 0票数 0

由于内存问题,我有一些崩溃。我得到的日志或多或少类似于这些日志:

代码语言:javascript
运行
复制
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 557942800 byte allocation with 25165824 free bytes and 374MB until OOM, target footprint 169310272, growth limit 536870912
       at com.appacoustic.rt.domain.calculator.processing.ToDoubleSamplesKt.toDoubleSamples(ToDoubleSamplesKt.java:25)
       at com.appacoustic.rt.domain.calculator.ReverbTimeCalculator.invoke(ReverbTimeCalculator.java:25)
       at com.appacoustic.rt.framework.audio.recorder.Recorder.stop(Recorder.java:25)
       at com.appacoustic.rt.framework.audio.recorder.Recorder$stop$1.invokeSuspend(Recorder.java:12)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:2)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:2)
       at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.java:2)
       at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuationKt.java:120)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:9)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:9)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:9)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:4)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:4)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:4)
       at com.appacoustic.rt.presentation.measure.MeasureViewModel$handleStartClicked$1$1.onFinish(MeasureViewModel.java:23)
       at com.appacoustic.rt.domain.ButtonStateHandler$start$1.onFinish(ButtonStateHandler.java:4)
       at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:127)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7397)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
代码语言:javascript
运行
复制
Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 216662032 byte allocation with 25165824 free bytes and 43MB until OOM, max allowed footprint 516134168, growth limit 536870912
       at com.appacoustic.rt.domain.calculator.processing.SchroederIntegralKt.schroederIntegral(SchroederIntegralKt.java:1)
       at com.appacoustic.rt.domain.calculator.ReverbTimeCalculator.calculatePosition(ReverbTimeCalculator.java:1)
       at com.appacoustic.rt.domain.calculator.ReverbTimeCalculator.invoke(ReverbTimeCalculator.java:7)
       at com.appacoustic.rt.framework.audio.recorder.Recorder.calculateReverbTime(Recorder.java:7)
       at com.appacoustic.rt.framework.audio.recorder.Recorder.stop(Recorder.java:15)
       at com.appacoustic.rt.framework.audio.recorder.Recorder$stop$1.invokeSuspend(Recorder.java:12)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:2)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:2)
       at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.java:2)
       at kotlinx.coroutines.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuationKt.java:120)
       at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(CancellableKt.java:10)
       at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.java:8)
       at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.java:8)
       at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(BuildersKt__Builders_commonKt.java:4)
       at kotlinx.coroutines.BuildersKt.launch(BuildersKt.java:4)
       at kotlinx.coroutines.BuildersKt.launch$default(BuildersKt.java:4)
       at com.appacoustic.rt.presentation.measure.MeasureViewModel$handleStartClicked$1$1.onFinish(MeasureViewModel.java:23)
       at com.appacoustic.rt.domain.ButtonStateHandler$start$1.onFinish(ButtonStateHandler.java:4)
       at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:127)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:193)
       at android.app.ActivityThread.main(ActivityThread.java:6669)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我在这里做的是音频处理操作。

例如:

toDoublesSamples

代码语言:javascript
运行
复制
fun ByteArray.toDoubleSamples(): DoubleArray = mapPairsToDoubles { a, b ->
    (a.toInt() and 0xFF or (b.toInt() shl 8)).toDouble()
}

inline fun ByteArray.mapPairsToDoubles(block: (Byte, Byte) -> Double) =
    DoubleArray(size / 2) { i ->
        block(
            this[2 * i],
            this[2 * i + 1]
        )
    }

或者这个:

schroederIntegral

代码语言:javascript
运行
复制
fun DoubleArray.schroederIntegral(): DoubleArray {
    val out = DoubleArray(size)
    for (index in indices) {
        out[index] = this[index] * this[index]
    }

    var aux = out[0]
    for (index in 1 until size) {
        aux += out[index]
        out[index] = aux
    }

    return out
}

我不太确定这里出了什么问题。我想这与足够的内存消耗有关,但我最多使用了1秒的44100赫兹信号。

当然,这是一件很愚蠢的事情,可能与双倍浪费过多的空间或类似的东西有关。但我不知道怎么解决。

顺便说一句,车祸有点随机。这种情况并不总是发生。

如果你想深入研究的话,回购就在这里:https://github.com/soygabimoreno/RT

有什么办法解决吗?:-)

EN

回答 1

Stack Overflow用户

发布于 2020-11-01 09:26:33

这是个愚蠢的错误。由于另一个地方的状态问题,我给AudioRecord.startRecording打了两次电话。

顺便说一下,我收到了一个-38错误。实际上,我开始录制,在记忆错误发生的那一刻它就停止了。

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

https://stackoverflow.com/questions/64292577

复制
相关文章

相似问题

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