4 Replies Latest reply on Feb 26, 2008 11:51 AM by Gaurav J

    Garbage Collecton of Strings

    RakhiMadaan
      My problem is, While profiling my application, I see a lot of String objects getting cumulated, even though I am assigning them to null, even after forced garbage collection. What is the way to make Strings availble for garbage collection?
        • 1. Re: Garbage Collecton of Strings
          anirudhs Level 2
          Hi,

          There's no special case for Strings in garbage collection. Any actionscript object is eligible for garbage collection once there are no more references to it.

          It would be great if could you give us a small piece of code that exhibits the behavior you mentioned.
          • 2. Re: Garbage Collecton of Strings
            RakhiMadaan Level 1
            Hi Anirudh,

            Thanks for your response. I have tried in two different cases:
            First one:

            var count:int = 0;
            for(var i:int=0;i<100; i++)
            {
            count++;
            var str:String = new String(count);
            str = null;
            }
            Second case:

            var count:int = 0;
            for(var i:int=0;i<100; i++)
            {
            count++;
            var str:String = new String("Hello World") + new String(count);
            str = null;
            }

            In the first case, the number of Strings in the Profiler get garbage collected, but in the second case it keeps on adding by increments of 100 and never get garbage collected.
            • 3. Re: Garbage Collecton of Strings
              anirudhs Level 2
              Strange. Can't seem to find any problem when I run your second case code with profiler. Could you show screenshots for first and second case?

              And, you are using Flex Builder 3 release version, not beta right?
              • 4. Re: Garbage Collecton of Strings
                Gaurav J Adobe Employee
                It seems in the second case when you are concatenating the string - the player is doing some string interning.

                The situation is no as bad as you described - I don't see 100 string hanging around but yes few of them seems to hand around after couple of calls.

                I would suggest you to submit a bug at http://bugs.adobe.com/flex

                Thanks,
                Gaurav Jain
                Flex SDK Team