Pushing the boundaries

…couldn’t be any simpler!

Archive for January 31st, 2007

native function

Posted by vijayram on January 31, 2007

Ok, this is a cool modifier. While I was looking through the notes on ActionScript 3.0, I did notice a reserved keyword called “native”. I had worked with native implementation in JAVA(JNI), so this really got me excited.Why?!

The reason being, the use of native functions indicates that the method is implemented externally. In a DLL maybe? ;) . So, there maybe possiblities to call native windowsAPI from the swf…hmmm. Using this abstract modifier means that the method implementation is not provided in the class.Because an external method declaration provides no actual implementation, there is no method body; the method declaration simply ends with a semicolon and there are no braces ({ }) following the signature.

native function functionName();
class className {
native function methodName();
}

So I started rummaging through the Flash Player code, and voila they use native functions as a part of implementation. What this means is that the native functions available to the Virtual Machine is called for through this function call using ActionScript.

package
{
//pseudo-final – no user class can extend Class
public dynamic class Class
{
// {DontEnum,DontDelete,ReadOnly}
public native final function get prototype()

// Class.length = 1 per ES3
// E262 {ReadOnly, DontDelete, DontEnum }
public static const length:int = 1;
}
}

The above is the actual code for a top level Class construct in the Virtual Machine which is available on tamarin.
Ok, the next obvious step, can I call for it from my code and override it if possible?!

Sadly not!!!! It turns out that Flash Player uses this internally and I cannot use it in my code as explained here.

Posted in AS 3.0, Adobe, Flash, Programming | Leave a Comment »

Garbage Collector

Posted by vijayram on January 31, 2007

Adding to the post on Stacks and Heaps, I had to link to this blog about the internal workings of Garbage Collector in ActionScript 3.0.

Grant Skinner on Resource Management . If that’s not enough, he has published his talks on Garbage Collector using visual simulators here.

*Some side notes:
- You cannot delete class members in ActionScript 3, if you want to cause a variable to no longer reference an object or value in memory, you should set your variable’s value to null instead of deleting it. [ myVar = null; ]
If all variable references to an object are null, the Garbage Collector will mark it for deletion and it will eventually be cleared from memory.
There is a post hereby Gordon Smith explaning the same.
- Ted Patrick has an interesting post on “flash.system.System.totalMemory” saying it just represents the memory allocated to the FlashPlayer. So it might not be the best util to check for memory leaks when you remove objects by setting it to null. You can learn about System.totalMemory here.
- FlashLite has this profiling for sometime now showing the heap memory usage. Pretty cool using the emulator tool. Any questions on that can be directed to IndiMad which is managed by Mariam.

Technorati Tags: , , ,

Posted in AS 3.0, Adobe, Flash, Programming | Leave a Comment »