内存泄漏&的OutOfMemoryError

时间:2018-02-13 14:59:15

标签: android memory-leaks out-of-memory

所以我试图找出我的应用程序崩溃的原因

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 128887990 byte allocation with 16777216 free bytes and 76MB until OOM
   at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
   at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
   at java.lang.StringBuilder.append(StringBuilder.java:216)    

我已经阅读了几个帖子,但他们都指向一个位图图像,我没有使用任何位图,所以我想也许我有内存泄漏可能会导致这个,所以我安装了泄漏,它只显示以下泄漏:

com.google.android.gms.internal.zzcfi.zzfus
references com.google.android.gms.common.api.internal.zzci.zzful
references com.google.android.gms.common.api.internal.zzck.zzfuk
com.tech.activity.dashboard instance

我在谷歌,Stackoverflow,Github和泄漏金丝雀上搜索过,我找不到这个漏洞或如何修复的参考。我相信这是来自我的google play services location,但是这会导致我看到的OOM错误吗?有人能指出我正确的方向吗?

**编辑** 正如评论指出这应该是一个字符串生成器问题,我从来没有改变我的字符串生成器的工作方式,因为我第一次发布应用程序,这是我的Stringbuilder来源AccessibilityNodeInfo,我在这里做错了吗?

public void processEvent(final AccessibilityNodeInfo source)
{
    final StringBuilder sb = new StringBuilder();
    processSubEvent(source, 0, sb);

    processUIText(source, sb.toString().toLowerCase());
}

private void processSubEvent(final AccessibilityNodeInfo source, final int n, final StringBuilder sb) {
    for (int i = 0; i < n; ++i){
        sb.append("\t");
    }

    if (source != null){
        sb.append(tools.getText(source));
        sb.append("\n");
        final int childCount = source.getChildCount();

        for (int i = 0; i < childCount; i++)
        {
            //Log.e(TAG, "Last UI: " + lastUIText);
            AccessibilityNodeInfo child = source.getChild(i);
            processSubEvent(child, n + 1, sb);

            child.recycle();
            }
        }
}

这是如何使用信息的示例:

private void processUIText(AccessibilityNodeInfo source, final String text)
{
   if (text.contains("hello") && !text.contains("hello again"){
        tools.showToast("Hello Reached");
   }
}

1 个答案:

答案 0 :(得分:0)

  

这是如何使用信息的示例:

然后不要建立一个字符串。建立一个boolean。类似于此的东西应该有效:

class Whatever {
    private boolean helloSeen=false;
    private boolean helloAgainSeen=false;

    public void processEvent(final AccessibilityNodeInfo source)
    {
        processSubEvent(source);
    }

    private void processSubEvent(final AccessibilityNodeInfo source) {
        if (source != null){
            String text=tools.getText(source);

            if (text.contains("hello")) {
                helloSeen=true;
            }

            if (text.contains("hello again")) {
                helloAgainSeen=true;

            }

            if (!helloSeen || !helloAgainSeen) {
                final int childCount = source.getChildCount();

                for (int i = 0; i < childCount; i++)
                {
                    //Log.e(TAG, "Last UI: " + lastUIText);
                    AccessibilityNodeInfo child = source.getChild(i);
                    processSubEvent(child);

                    child.recycle();
                }
            }
        }
    }
}

processEvent()返回后,helloSeenhelloAgainSeen将反映您的邮件是否在任何地方遇到过。

相关问题