Actionscript 3 Air应用程序挂起,而不是抛出MemoryError 我试图通过创建一个很长的字符串使我的应用程序抛出MemoryError,但它挂起而不是抛出。

Actionscript 3 Air应用程序挂起,而不是抛出MemoryError 我试图通过创建一个很长的字符串使我的应用程序抛出MemoryError,但它挂起而不是抛出。,actionscript-3,apache-flex,air,out-of-memory,freeze,Actionscript 3,Apache Flex,Air,Out Of Memory,Freeze,我用发布版和调试版的AIRSDK3.4和3.8尝试了这一点。 有时,当我以强制方式关闭应用程序时,eclipse会显示类似于“应用程序退出”的内容,错误代码为:内存不足 我还注意到控制台在执行代码后包含行[Unload SWF]myapp.SWF(如果在加倍字符串后添加trace(str.length),您将看到它发生在length369098752之后) 您可以在这里看到,这是导致内存错误的合法方式 那么,我怎样才能真正抓住那些记忆错误,而不是让应用程序崩溃呢? <?xml versio

我用发布版和调试版的AIRSDK3.4和3.8尝试了这一点。 有时,当我以强制方式关闭应用程序时,eclipse会显示类似于“应用程序退出”的内容,错误代码为:内存不足

我还注意到控制台在执行代码后包含行
[Unload SWF]myapp.SWF
(如果在加倍字符串后添加
trace(str.length)
,您将看到它发生在length
369098752
之后)

您可以在这里看到,这是导致
内存错误的合法方式

那么,我怎样才能真正抓住那些记忆错误,而不是让应用程序崩溃呢?

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                        applicationComplete="onCreation(event)"                     
                       >
    <fx:Script>
        <![CDATA[
            import flash.utils.setInterval;

            import mx.controls.Alert;
            import mx.events.FlexEvent;

            import avmplus.getQualifiedClassName;

            protected var vectors:Vector.<Vector.<uint>>= new Vector.<Vector.<uint>>();
            protected function onCreation(event:FlexEvent):void{
                loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,onUncaughtError);
                var serverString:String = unescape(Capabilities.serverString);
                trace('vm version: '+System.vmVersion);
                setInterval(increaseMemoryUsage,100);
            }

            protected function increaseMemoryUsage():void{
                try{
                    var vector:Vector.<uint> = new Vector.<uint>();
                    vector.length = 1024*1024/4;//1MB
                    vectors.push(vector);
                    System.gc();
                    trace(vectors.length*1+'MB');
                    trace('total: '+System.totalMemoryNumber+', private: '+System.privateMemory+', free: '+System.freeMemory);
                    totalMemoryDisplay.text=''+int(System.totalMemoryNumber/(1024*1024))+'MB';
                }catch(e:MemoryError){
                    trace('it catches!');
                    Alert.show('memoryError');
                }catch(e:Error){
                    trace('error'+e.errorID);
                }
            }


            protected function onUncaughtError(e:UncaughtErrorEvent):void{
                trace('it is uncaught!');
            }
        ]]>
    </fx:Script> 
    <s:Label id="totalMemoryDisplay" />
</s:WindowedApplication>
这是我的密码:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                        creationComplete="onCreation(event)"                        
                       >
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.FlexEvent;         
            import avmplus.getQualifiedClassName;

            protected var str:String = 'ssssssssssssssssssssss';
            protected function onCreation(event:FlexEvent):void{
                var serverString:String = unescape(Capabilities.serverString);
                try{
                    while(true){
                        str+=str;
                    }
                }catch(e:MemoryError){
                    Alert.show('memoryError');
                }
            }           
        ]]>
    </fx:Script>   
</s:WindowedApplication>

更新: 我改进了测试应用程序,现在您可以清楚地看到没有抛出错误或未捕获的错误。 当内存使用量达到1700-1750MB时,它会崩溃。 我在bugbase中发现了一些类似于我的案例的bug,但它们与AIR2.x相关,并标记为已修复/非bug。我在AIR3.x上找不到类似的bug

有人能繁殖吗?

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                        applicationComplete="onCreation(event)"                     
                       >
    <fx:Script>
        <![CDATA[
            import flash.utils.setInterval;

            import mx.controls.Alert;
            import mx.events.FlexEvent;

            import avmplus.getQualifiedClassName;

            protected var vectors:Vector.<Vector.<uint>>= new Vector.<Vector.<uint>>();
            protected function onCreation(event:FlexEvent):void{
                loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR,onUncaughtError);
                var serverString:String = unescape(Capabilities.serverString);
                trace('vm version: '+System.vmVersion);
                setInterval(increaseMemoryUsage,100);
            }

            protected function increaseMemoryUsage():void{
                try{
                    var vector:Vector.<uint> = new Vector.<uint>();
                    vector.length = 1024*1024/4;//1MB
                    vectors.push(vector);
                    System.gc();
                    trace(vectors.length*1+'MB');
                    trace('total: '+System.totalMemoryNumber+', private: '+System.privateMemory+', free: '+System.freeMemory);
                    totalMemoryDisplay.text=''+int(System.totalMemoryNumber/(1024*1024))+'MB';
                }catch(e:MemoryError){
                    trace('it catches!');
                    Alert.show('memoryError');
                }catch(e:Error){
                    trace('error'+e.errorID);
                }
            }


            protected function onUncaughtError(e:UncaughtErrorEvent):void{
                trace('it is uncaught!');
            }
        ]]>
    </fx:Script> 
    <s:Label id="totalMemoryDisplay" />
</s:WindowedApplication>

>=新向量。();
受保护的函数onCreation(事件:FlexEvent):void{
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UncaughtU ERROR,onUncaughtError);
var serverString:String=unescape(Capabilities.serverString);
跟踪('vm版本:'+System.vmVersion);
设置间隔(增加内存,100);
}
受保护的函数increaseMemoryUsage():void{
试一试{
变量向量:向量。=新向量。();
vector.length=1024*1024/4;//1MB
向量。推(向量);
gc();
跟踪(向量长度*1+'MB');
跟踪('total:'+System.totalMemoryNumber+',private:'+System.privateMemory+',free:'+System.freeMemory+);
totalMemoryDisplay.text=''+int(System.totalMemoryNumber/(1024*1024))+'MB';
}捕获(e:记忆错误){
trace(“它抓住了!”);
警报。显示('memoryError');
}捕获(e:错误){
跟踪(“错误”+e.errorID);
}
}
受保护函数onUncaughtError(e:UncaughtErrorEvent):无效{
痕迹(“它是未捕获的!”);
}
]]>

不,这不是一个解决方案