2 Replies Latest reply: Oct 27, 2009 4:32 PM by zazzo9 RSS

    With c code: return AS3_String("foobar"), what about AS3_Release?

    philipSe32

      When I have a c function that returns an AS3_Val created via AS3_String() or AS3_StringN() or similar, I assume the need for AS3_Release doesn't arise.  The API spec for AS3_String() states that the newly created string must be released.  I can't see how to do that when the newly created string is returned.  Also, I note that in the stringecho sample, the string is returned in this way and there is no release.  Am I right?

        • 1. Re: With c code: return AS3_String("foobar"), what about AS3_Release?
          audioMirror

          I wondered about this too.  I believe that no release is necessary, because the object is a return parameter back to the AS3 world.  It wouldn't make sense to release an object, and then pass a dead reference back.  Some code in the alchemy library must be doing the release (after which time AS3 will deal with the reference by counting it during garbage collection).

           

          This is just a guess -- but I have never seen it used any other way.  I wish there were more documentation -- but alchemy is only a research project (which has had no updates since last December).

          • 2. Re: With c code: return AS3_String("foobar"), what about AS3_Release?
            zazzo9 Community Member

            When a value is returned to Actionscript from a C function, its C counterpart is released after conversion to Actionscript and before the final return.

              public function fromReturnRegs(regs:Object):*
              {
                var a:Array = [regs.eax];
                var result:* = fromC(a);
            
                destroyC(a); // <-- here
                return result;
              }
            

             

            It is possible this code is somehow buggy, but it is obviously intended that Alchemy handle the releasing of return values for you.  Similarly, passed arguments are automatically released.