Skip navigation
evilches
Currently Being Moderated

ANE: How to return a ByteArray and how to release its memory?

May 9, 2012 9:07 AM

I would like to return a ByteArray from my ANE. The bytes will be allocated from the native side (in C). Is this possible? If so, does the AS side become responsible for deallocating the memory, using the normal garbage collector, or should the native side?

 
Replies
  • Currently Being Moderated
    May 14, 2012 10:32 PM   in reply to evilches

    I haven't tried the ByteArray, but I couldn't think of any reasons that you can't.

    You can clean up your C side code at least in two ways:

    1: put clean up code in contextFinalizer, it would be called after Flex side calls dispose(), but only triggers when garbarge collection runs, which means not controlled by you

    2: write another method to clean up as you do for your other functions.

     
    |
    Mark as:
  • Currently Being Moderated
    May 15, 2012 9:41 AM   in reply to evilches

    it's owned by the ANE, but the ANE is owned by your main application. So, they should have the application id, (not 100% sure). But what I have tried it. use exit 0;  in Objective-C side, it would exit the whole application.

     

    I didn't get your second part. Generally, after you call the context.dispose(), it will wait for the garbarge collection run, when gc runs, the objective-c side will trigger the finalizer method, some cleaning up code should be addressed there, or it will stuck in the memory until you application dies.

     

    Please give some details about your concerns.

     
    |
    Mark as:
  • Currently Being Moderated
    May 16, 2012 10:27 AM   in reply to evilches

    I am not sure if you can redirecting a pointer from C to Flex. My understanding is you have two byteArray memory chuck, one in C, the other in Flex.

    Basically, I agree with your second approach. Once you get the ByteArray value from C, you can just dipose the ExtensionContext.

     

    That's what I am doing for my application, it works fine, at least. Maybe redirecting a pointer can save some memories, but I have no idea how to achieve that.

     
    |
    Mark as:
  • Currently Being Moderated
    May 17, 2012 8:17 PM   in reply to evilches

    I haven't found a way to track the application memory when including ANE since obviously we cannot use profile.

    Instead of calling disposing and waiting for the Flex to do the gc, I currently prefer maunally cleaning up all the memory in the Objective-C side. Specially when you calling some visual container or component from Objective-C side, if you just call dispose method, and the Flex doesn't do the gc, everything will be stuck there sometimes......

     

    I just did an ANE to enable WebGL content from Flex and that's painful when you can dispose, the WebGL page remains sitting there.

     

     

    Good Luck~

     
    |
    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