Extension Initializer and Finalizer in C

Opt In Image
Early bird offer on the ANE eBooks


Buy any Easy Native Extensions 2nd Edition package and get our $99 iOS + Android ANE Template completely free before the end of June 2015.



  • step-by-step guide to making your iOS extension in under an hour
  • library for data conversion between ActionScript and native code
  • tutorials
  • infographics
  • code included

The Extension Initializer and Finalizer are the entry and exit points to your native extension. They are also two of the ingredients that make your extension known to the world and make it distinguishable from other extensions in an app. This is why they need to have unique names. Their signatures however need to be exactly as prescribed by AIR. Today we look at what these are in the AIR C API.

Extension Initializer in C – FREInitializer

The C version of the Extension Initializer is a function with the following signature:

 It is called when your extension is first loaded by an app and its role is to set the following:

  • extDataToSet – a pointer to a pointer to data that the extension may need. It is allocated in FREInitializer. It can also be NULL if you don’t need extension-specific global data.
  • ctxInitializerToSet – a pointer to another function, the Extension Context Initializer, which will be called when your extension instantiates an Extension Context
  • contextFinalizerToSet – a pointer to a function, the Extension Context Finalizer, which will be called when your Extension Context is destroyed.

 Here is an example implementation of a FREInitializer:

Extension Finalizer in C – FREFinalizer

This is the C signature of the Extension Finalizer function:

You may notice a familiar argument here:

  • extData is a pointer to the data that was allocated in FREInitializer, in other words it’s the same as extDataToSet*. FREFinalizer’s role is to tidy up after the extension, so any data that FREInitializer may have allocated is deallocated here. Or, if no data was allocated and extDataToSet was left NULL, nothing is done with extData.

Here is what the respective implementation of FREFinalizer would look like:

What’s next?

Next we will look at what’s an Extension Context and what’s an Extension Context Initializer and Finalizer.

Then we will see in what order all of these initializers and finalizers are called when your ANE is loaded and when it’s unloaded.

We will also have a look at the Java versions of the Extension Initializer and Finalizer.

Over to you

Do you have a convention for naming your Extension Initializer and Finalizer? What is it? Tell us in the comments below.

Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">