Skip to main content
May 9, 2012
Question

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

  • May 9, 2012
  • 7 replies
  • 1580 views

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?

This topic has been closed for replies.

7 replies

Inspiring
May 15, 2012

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.

May 15, 2012

Thanks for the answer. Do you mean then that the newly allocated memory is "owned" by the native side of the ANE? My biggest doubt was if, when the ByteArray on the AS side gets garbage collected, it disposes the memory allocated by the native side. If such was the case, then it should not be disposed of on the native side.

Inspiring
May 15, 2012

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.