lundi 23 novembre 2015

Does the same String value always amount to the same String reference in AS3?

In AS3, do two Strings with the same value always have the same exact reference, without exception? In particular, I'm wondering if things like concatenated strings and strings returned from a web service can create duplicate instances of the same exact value.

For instance:

class Example
{
    const MY_STRING:String = "Example";
    .
    .
    .
    private function myWebMethodResultHandler(pResult:ResultEvent):void
    {
        var myWebMethodString:String = pResult.result as String;
        trace(myWebMethodString === MY_STRING); // returns true;
    }
    .
    .
    .
    private function someOtherFunction():void
    {
        var str1:String = "Ex";
        var str2:String = "ample";
        var concatenatedString:String = str1 + str2;
        trace(concatenatedString === MY_STRING); // returns true;
    }
}

Is it absolutely guaranteed that in every case, including the ones above, that two Strings in AS3 with the same value are also the same exact instance with the same exact reference, or are there any cases at all in which Strings could be stored separately and as duplicate instances, taking up twice as much memory (and causing String comparisons to be more complicated internally than just comparing two 32-bit references)?

Aucun commentaire:

Enregistrer un commentaire