本文介绍了无效的堆地址和致命信号 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每隔一段时间我的应用就会崩溃,我的日志会显示:

Every so often my app will crash and my log will read:

@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)

有时code=2,但总是致命信号11无效堆地址.

我已经尝试研究这意味着什么以及如何解决它.这个话题最有帮助;但是,我仍然没有解决方案.

I've tried researching what this means and how to fix it. This thread has been the most helpful; however, I'm still without a solution.

当我运行几个 AsyncTasks 来下载多个图像时发生错误.

The error occurs when I run a couple of AsyncTasks to download several images.

这是我的主要AsyncTask

public class FetchArtistImages extends AsyncTask<Void, Integer, String[]> implements Constants {

private final WeakReference<Context> contextReference;

public FetchArtistImages(Context context) {
    contextReference = new WeakReference<Context>(context);
}

@Override
protected String[] doInBackground(Void... params) {
    String[] projection = new String[] {
            Audio.Artists._ID, Audio.Artists.ARTIST
    };
    String sortOrder = Audio.Artists.DEFAULT_SORT_ORDER;
    Uri uri = Audio.Artists.EXTERNAL_CONTENT_URI;
    Cursor c = contextReference.get().getContentResolver()
            .query(uri, projection, null, null, sortOrder);
    ArrayList<String> artistIds = new ArrayList<String>();
    if (c != null) {
        int count = c.getCount();
        if (count > 0) {
            final int ARTIST_IDX = c.getColumnIndex(Audio.Artists.ARTIST);
            for (int i = 0; i < count; i++) {
                c.moveToPosition(i);
                artistIds.add(c.getString(ARTIST_IDX));
            }
        }
        c.close();
        c = null;
    }
    return artistIds.toArray(new String[artistIds.size()]);
}

@Override
protected void onPostExecute(String[] result) {
    for (int i = 0; i < result.length; i++) {
            new LastfmGetArtistImages(contextReference.get()).executeOnExecutor(
                    AsyncTask.THREAD_POOL_EXECUTOR, result[i]);
    }
    super.onPostExecute(result);
}

尽管我已经尝试研究这是怎么回事,但在修复它时我仍然发现自己迷失了方向.如果有人有一些见解,我肯定会很高兴看到它.每次我 execute 我的 AsyncTasks 时都不会抛出错误,但我找不到太多模式来帮助确定发生这种情况的原因.关于 fatal signal 11,SO 上还有其他几个线程,但在我的情况下,它们没有提供太多帮助.

Even though I've tried researching what's up with this, I still find myself lost when it comes to fixing it. If anyone has some insight, I'd definitely appreciate seeing it. The error isn't thrown every time I execute my AsyncTasks, but I can't find much of a pattern to help isolate why this is occurring. There are a couple of other threads on SO about fatal signal 11, but they don't provide much help in my case.

推荐答案

我刚刚遇到了同样的问题,并使其处于可重现的状态.这是我得到的错误:

I just ran into the same issue and had it at a re-producable state. This is the error I was getting:

08-04 17:37:05.491:A/libc(4233):@@@ ABORTING:dlfree 中无效的堆地址08-04 17:37:05.491:A/libc(4233):0xdeadbaad 处的致命信号 11 (SIGSEGV)(代码 = 1)

它归结为同时从两个不同的线程进行的函数调用.

What it boiled down to is a function call being made from two different threads at the same time.

更具体地说,这个函数是BluetoothSocket 的close() 方法.

More specifically, this function was BluetoothSocket's close() method.

我检查了源代码在本网站 ,并且调用未同步(不确定是否更改,因为它来自 Android 2.1).

I checked the source code at this website , and the call is not synchronized (not sure if this changed since it is from Android 2.1).

无论如何,您是否有类似的场景,即从多个线程进行函数调用?从您展示的源代码中无法确定.

At any rate, do you maybe have a similar scenario where a function call is made from multiple threads? Can't say for sure from the source code you're showing.

你也试过不使用 THREAD_POOL_EXECUTOR 吗?根据android开发指南:

Also have you tried not using THREAD_POOL_EXECUTOR? According to the android dev guide:

首次引入时,AsyncTasks 在单个后台线程上串行执行.从 DONUT 开始,这已更改为允许多个任务并行操作的线程池.从HONEYCOMB开始,任务在单线程上执行,避免并行执行导致的常见应用错误.

这篇关于无效的堆地址和致命信号 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:20