0

I have this weird problem for a while and try to solve it to look up on the net for proper solution but still I am clueless.

When I check my application's memory usage with flex profiler (4.6) the portion of String keep increasing and eventually reach the point of crash.

And I pin pointed where this increasing occurs from my application's source code.

It is the local string variable that I passed to Json.decode(). It never cleared. All the instance of the json string that I got from the socket server remains in the memory til app crashes even if profiler says there is 0 path to the String.

I don't know how to clear these Strings. It only keeps growing.

Please help me. I have been struggled with this for a week now.

Thanks for any support in advance.

portion of my source code that I think the source of the leak is as following.

        protected function evtserverReseved(event:ProgressEvent):void{

            var tmpArr:ByteArray = new ByteArray();
            var tempByteArray:ByteArray = new ByteArray();
            socEvtServer.readBytes(tmpArr, 0, socEvtServer.bytesAvailable);

            tempByteArray.writeBytes(leftOverMessageNotify, 0, leftOverMessageNotify.length);
            tempByteArray.writeBytes(tmpArr, 0, tmpArr.length);

            leftOverMessageNotify = new ByteArray();
            parseByteArray(tempByteArray);  
        }

        private function parseByteArray(rawArray:ByteArray):void{
            if(( rawArray[0] == 0x30 || rawArray[0] == 0x31 ) && rawArray[1] == 0x00 ){
                var log:String = "";
                for(var i:int=0; i<16; i++){
                    if(rawArray[i]==0){
                    }else{
                        log += rawArray[i]-48;
                    }
                }

                sizeOfFullListNotify = uint(log);
                commonFunction.printLog("Event Server eventNotify sizeOfFullListNotify=" + sizeOfFullListNotify);
                rawArray.position = 16;
            }

            var tempIdx:uint = rawArray.position;
            var tempLength:uint = rawArray.length;

            if(sizeOfFullListNotify <= tempLength - tempIdx){
                var tempArray:ByteArray = new ByteArray();
                var tempLeftOver:ByteArray = new ByteArray();
                var j:uint;
                for(j=0; j <sizeOfFullListNotify ; j++){
                    tempArray[j] = rawArray[j+tempIdx];
                }
                var euckrString:Object = tempArray.readMultiByte( tempArray.length,"euc-kr").replace("  ","").replace("\n","");

                //commonFunction.printLog("Total memory=" + flash.system.System.totalMemory +", Free memory=" + flash.system.System.freeMemory + ", Event Server eventNotify JSON 수신 data size=" +euckrString.toString().length+ ", body=" + euckrString.toString() );

                var ob:Object = com.adobe.serialization.json.JSON.decode(euckrString.toString());

                commonFunction.printLog("Total memory=" + flash.system.System.totalMemory +", Free memory=" + flash.system.System.freeMemory + ", Event Server eventNotify JSON data size=" +euckrString.length+ ", body=" + euckrString );

                if(ob.method != null){
                    //gridBox.DT_HOUSE.addItemAt(ob,0);
                    gridBox.DT_HOUSE.push(ob);

                    totlaReceivedList++;
                }else if(!(ob.result is String)){
                    //confirm for registerEventNotify
                    commonFunction.printLog("confirm for registerEventNotify");
                }                                       
                if(sizeOfFullListNotify < tempLength - tempIdx){
                    for(var k:uint=0; k <tempLength-tempIdx-sizeOfFullListNotify ; k++){
                        tempLeftOver[k] = rawArray[k+j+tempIdx];
                    }
                    parseByteArray(tempLeftOver);
                }else{
                    //leftOverMessageNotify = new ByteArray();
                }
            }else{  
                //leftOverMessageNotify = rawArray;
                for(var i:int = 0 ; i<rawArray.length ; i++){
                    leftOverMessageNotify[i] = rawArray[i];
                }
                rawArray = null;
            }
        }

var euckrString:Object(String) is the portion that never cleared from the memory. It keeps stacking till crashes.

  • You try assign "nothing" value to the object of the end the function? – matilu Dec 20 '13 at 15:21
  • Thanks for ur response @matilu, I tried euckrString=null or even euckrString="" but still the same problem remains. I suspect problem more like why flex gc does not collect garbage which has 0 path. – user3123076 Dec 20 '13 at 15:29
  • If the problem is that the GC works when needed, rather than try to force her to take the decision. But the value of the waste will be less if you leave "nothing", at least. – matilu Dec 20 '13 at 15:40
  • String eventually has been garbage collected on runtime I checked, Somehow only Flex profiler showed those String remains in the memory. I don't know why though. Makes me confuse and found out the orgin of memory leaking in my app was from the other part of source code which misused timer object. Thanks @matilu for ur help though. – user3123076 Dec 22 '13 at 14:50
  • Hit the force GC button frequently when using the profiler. It helps. – drkstr101 Dec 22 '13 at 15:08
  • possible duplicate of [Force Garbage Collection in AS3?](http://stackoverflow.com/questions/192373/force-garbage-collection-in-as3) – Paul Sweatte Jul 01 '15 at 18:25

0 Answers0