安卓:增加调用堆栈大小 [英] Android: Increase call stack size

查看:1750
本文介绍了安卓:增加调用堆栈大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有非常复杂的用户界面的应用程序,包含了许多布局其中嵌套在另一个。虽然创建另一个布局,我得了一个的StackOverflowError

I have an application with very complex UI, containing many layouts nested one in another. While Creating another layout, I've caught a StackOverflowError

想知道,我创建了两个测试的例子:

Wondering, I've created two test examples:

1)Hello World应用程序有以下 XML 的主要活动

1) Hello world application with following xml for main Activity

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <!-- ...So on 30 times... -->

                <FrameLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" >

                </FrameLayout>

            <!-- ...So on 30 times... -->

        </FrameLayout>
    </FrameLayout>
</FrameLayout>

引起的StackOverflowError在绘制布局(导致每一个布局递归绘制其子)

causes StackOverflowError while drawing the layout (cause every layout recursively draws it's children)

2)以下的情况下,测试

2) The following test case

public class TestOverflowActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        overflow(0);
    }

    private void overflow(int i){
        android.util.Log.i("Stack depth:", " = " + i);
        overflow(i+1);
    }
}

原因的StackOverflowError 深度约260-270电话。

causes StackOverflowError on depth about 260-270 calls.

栈元素的第二个测试案例每个呼叫需要4个字节的返回地址 + 4个字节参数 = 8个字节。这有可能是的Dalvik的虚拟机保留了一点信息中的每个元素,但即使每件16个字节* 260通话=约4K字节的最大总堆栈大小。这似乎并不足够。

Every call of stack element for second test case takes 4 bytes for return address + 4 bytes for parameter = 8 bytes. It's possible that Dalvik's VM keeps a bit more info in every element, but even 16 bytes per element * 260 calls = about 4Kbytes for maximum overall stack size. This does not seem enough.

有没有什么办法来增加最大堆栈大小?

Is there any way to increase maximum stack size?

推荐答案

<打击>您不能改变在Android的线程堆栈大小。这是 8KB 据我所知。 @马丁Cazares显示了如何设置这种对可能很多/所有设备,请参阅下面我不认为你打算窝布局元素30深的那样。在简单的答案是不这样做。当然,还有另一种方式。

You can't change the thread stack size on Android. It is 8KB as far as I know. @Martin Cazares shows how to set this on probably many/all devices, see below. I don't think you're intended to nest layout elements 30 deep like that; the simplistic answer is "don't do that". Surely there's another way.

这篇关于安卓:增加调用堆栈大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆