Skip navigation
Currently Being Moderated

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

Oct 27, 2009 8:47 AM

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?

  • Currently Being Moderated
    Oct 27, 2009 11:00 AM   in reply to philipSe32

    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).

    Mark as:
  • Currently Being Moderated
    Oct 27, 2009 4:32 PM   in reply to philipSe32

    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.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points