views:

70

answers:

2
+2  Q: 

any haXe GC tips?

Recently I am learning haXe for flash, and I have few actionscript3 experience.

HaXe is really good language.

I notice there is a delete operation in as3, Is there some like delete in HaXe? Is the "delete" about gc? Is there any tips for haXe newbie about memory management, thanks?

+6  A: 

I don't really know much about haxe, but the delete operator in as3 actually doesn't delete objects. You can't force deconstruction in as3 at all really. The delete operator is used to remove the reference to a property of a dynamic object. For example:

var foo:Object {
    a: "Hello, ",
    b: "world!,
    toString: function () { return a + b; }
}

foo.toString() // Hello, world!

This anonymous object is dynamic and properties can be added or removed. Much like a hash table. Now consider the following:

delete foo.b;
foo.toString(); // Hello, undefined

When the delete occurs, 'foo' releases its reference to the property 'b', making it undefined. The value of 'b' however is not necessarily removed from memory. If someone else is referencing the same value, it will most likely stick around. Thus, delete only removes references, not actual values and as such will not enable you to force garbage collection.

macke
thank you, helpful information.
guilin 桂林
+2  A: 

macke already explained what the delete operator does. For use in haXe please refer to this page: http://haxe.org/doc/advanced/magic

Thus the haXe equivalent of delete foo.b is untyped __delete__(foo, "b"). In case you intend to use it a lot, I suggest you put that into a function ;)

greetz
back2dos

back2dos