Jump to content
  • Advertisement
Sign in to follow this  
lephyrius

Scripting garbage collection and destructor

This topic is 2104 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've been thinking of using Squirrel as a scripting language.

My idea was to use the garbage collector as a memory manager:(squirrel as an example script)

class Model
{	
	constructor(filename)
	{
		model_id = load_model(filename);
	}

       destructor() 
       {
                unload_model(model_id);
       }
       								
	model_id = null;
}

Something like this.(load_model and unload_model is native functions that are really easy to bind no need to worry about binding complicated classes)

It's obvious that this isn't going to work. Because Squirrel is missing the destructor.

Am I thinking of something wrong?

Is there a reason why Squirrel doesn't have a destructor?

Am I just using scripting in a wrong way?

Are there any alternatives to Squirrel that is similar to it but with a destructor?

Should I rethink the problem with binding to the native functions?

Share this post


Link to post
Share on other sites
Advertisement

I've been thinking about this.

You are right it has really opened my eye to something also it's really nice and cache friendly to store models in that way.

The problem is that isn't scripting languages one the reasons of using a scripting language is to use the garbage collector.

 

Hmmmm...

Clean up after a level is loaded shouldn't be a problem when all the allocations are controlled by the engine itself. It certainly is faster to deallocate chunks of memory also more cache friendly.(almost feels like my C++ code becomes more C like)

The thing is that I was thinking that scripting should be more a part of the engine rather than just a slave to the engine.

Share this post


Link to post
Share on other sites

As a side note, GC collected languages generally have finalizers instead of destructors. They're almost the same thing but with an important difference: dtor is called deterministically while finalizer is called "at some point in time" immediately before object is cleared.

This gives an important implication: most of the time you need to "clear" (in gameplay terms) an object as a response to an action.

I've witnessed a dude cracking his head open at a bug originating exactly from this behaviour: he expected an object to go away immediately after dropping its reference. This of course wasn't the case and since he tied existence to visualization, some sprites appeared to be all over the place.

 

So, maybe this is not completely related to your needs but I hope it helps you thinking.

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!