class T1 :IEntity {
T1() {
registerEntity(this);
print("T1()");
}
~T1() { print("~T1()"); }
void process() { }
}
class T2 : IEntity {
T1 @t1; //this is the problem here
T2() {
registerEntity(this);
print("T2()");
}
~T2() {
print("~T2()");
}
void process() { }
}
void main() {
T2 t2;
killEntity(t2);
}
Argh.. simple thing isn't working.
I created a test program with two functions, registerEntity(asIScriptStruct *) which just throws it in a collection, and killEntity(asIScriptStruct *) which releases the entity twice: once for C++ holding onto it from the registerEntity call, and once for the killEntity call, then I remove it from the collection.
The following program behaves, in my understanding of how it should work, incorrectly:
That never calls ~T2(). If you remove the line I pointed out (T1 @t1) it works as expected. It also never calls T1 ctor(as it shouldn't).
What am I doing wrong here?
duh, didn't call the GC... I didn't realize that objects with internal references are always GC'd... is there a way to completely skip the GC and assume that I know how to manage my own memory?
registerEntity will hold onto a reference of an entity forever... I don't care about any other references to entities anywhere ever... can I just completely skip GCing for that object? if I get a null pointer in script then it can crash for all I care =)
registerEntity will hold onto a reference of an entity forever... I don't care about any other references to entities anywhere ever... can I just completely skip GCing for that object? if I get a null pointer in script then it can crash for all I care =)
Unfortunately not. I could have written AngelScript without garbage collection, but it wouldn't provide a safe environment for scripting.
I suggest you add a routine in your game loop to call the GC in iterative steps. At strategic moments, where speed is not of essence you should call the GC to perform a full cycle.
I suggest you add a routine in your game loop to call the GC in iterative steps. At strategic moments, where speed is not of essence you should call the GC to perform a full cycle.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement