Jump to content
  • Advertisement
Sign in to follow this  
RsblsbShawn

Argh.. simple thing isn't working.

This topic is 3960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
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);
}


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?

Share this post


Link to post
Share on other sites
Advertisement
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 =)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!