Skip to main content
Participant
October 10, 2012
Answered

String memory leak?

  • October 10, 2012
  • 2 replies
  • 1435 views

I've been programming for some time in AS3 and found a really weird problem with strings that for no apparent reason are hanging on the memory, the program below just changes the label.text property with a random string, it works fine but when i looked at the Flex profiler i noticed that the number of Strings is increasing steadly, i tried executing the garbage collector but didnt helped me.

Is this a memory leak? how can i solve it?

As I know this strings should be collected by the garbage collector because there are no objects referencing them, yet this is not happening for all the strings.

Heres the code and a screenshot of the Flex profiler showing the number of String instances.

<?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="windowedapplication1_creationCompleteHandler(event)">
<s:layout>
   
<s:BasicLayout/>
</s:layout>
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;

        protected var t:Timer=new Timer(10);

        protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
        {
            t.addEventListener(TimerEvent.TIMER,listener,false,0,true);
            t.start();
        }

        protected function listener(e:Event):void
        {
            var s:String=Math.random()+"-->";
            this.fx(s);
            s=null;
        }

        protected function fx(s:String):void
        {
            this.label.text=s;
        }
    ]]>
</fx:Script>
<fx:Declarations>
   
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="label" y="39" left="10" right="10" text="Label"/>
</s:WindowedApplication>

http://imageshack.us/a/img11/9716/stackw.png

This topic has been closed for replies.
Correct answer mcclone2001

Theres no such memory leak, Answered here

http://stackoverflow.com/questions/12821553/as3-string-memory-leak

2 replies

mcclone2001AuthorCorrect answer
Participant
October 10, 2012
chris.campbell
Legend
October 18, 2012

Thanks for the follow up!