Game Development Community

Unloading an imageMap?

by Vern Jensen · in Torque Game Builder · 08/27/2009 (1:46 am) · 5 replies

To allow my game to have a splash screen *while* loading graphics, I have moved most of the datablocks out of

/managed/datablocks.cs

into a different file, leaving in datablocks.cs *only* the files used for my game's logo and splash screens. Once the logo screen is done (it is an animation that uses about 5 sprites), I want to "free" these images (dispose, delete, whatever you want to call it) before manually loading datablocks.cs. Is there a call to do this? A call that tells the engine "I'm *never* going to use these images again, for the rest of the game. Get rid of them. Pretend I never loaded them. Free up their memory and VRAM usage entirely." ?

Obviously I could use .delete, but that only deletes the current reference. I want to free it up as if I never loaded it in the first place. Gone permanently.

#1
08/27/2009 (2:08 am)
Experimenting further, it seems that the code below does the job. Can anyone confirm that this is how you want to do it -- using .delete()?

deleteAllObjectsInSimSet( $managedDatablockSet );

function deleteAllObjectsInSimSet( %theSimSet )
{
	while (%theSimSet.getCount() > 0)
	{
		%object = %theSimSet.getObject(0);
		%theSimSet.remove(%object);	// Apparently this is unnecessary, but we do it anyway
		%object.delete();
	}
}
#2
08/27/2009 (11:01 am)
Hey Vern.

Have you looked at the safeDelete() function for this? I can't remember the particulars of why it is a more efficient way to remove and object but I recall a post by Melv that details it a bit.

EDIT

Patrick
#3
08/27/2009 (2:29 pm)
safeDelete() simply helps you avoid crashes. For instance, if you want to delete an object from within its own callback function, that can sometimes cause a crash, so you use safeDelete() instead.

No need for that in this case though.
#4
08/27/2009 (5:09 pm)
It doesn't seem that there is a way.

In this thread Stephen says that "If you are assuming that Torque will release memory back to the operating system, that does not happen."

Unfortunate.
#5
08/27/2009 (5:30 pm)
Bummer. What about from C++ then? Any way to free up system memory (unload a datablock) from C++? I've got the source and could export a method to script if the method is already there in the source.