Game Development Community

Deleting a datablock

by Bruno · in Torque Game Builder · 03/30/2008 (5:17 am) · 5 replies

Hi,

I'm creating a datablock in realtime :

new t2dImageMapDatablock(la9) {
imageName = "~/data/images/test.png";
imageMode = "FULL";
frameCount = "-1";
filterMode = "SMOOTH";
filterPad = "0";
preferPerf = "1";
cellRowOrder = "1";
cellOffsetX = "0";
cellOffsetY = "0";
cellStrideX = "0";
cellStrideY = "0";
cellCountX = "-1";
cellCountY = "-1";
cellWidth = "0";
cellHeight = "0";
preload = "0";
allowUnload = "1";
};


and i want to delete it on the fly too, after being used, and i delete it like this :

la9.delete();

and altough this seems to work, memory wise, it seems it's still there.
I made tests with loading\unloading several datablocks on the fly, and memory won't go down when i
delete them.
What's the correct way to remove the datablocks from memory ?

thanks,
Bruno

#1
03/30/2008 (12:15 pm)
%myvariable = new t2dImageMapDatablock(la9)
{
....
}

%myvariable.safedelete();
#2
03/30/2008 (12:40 pm)
Would safeDelete really do anything different in this case?

There is no special "release memory" command, delete or safedelete should do it. It is possible there is a memory leak, but I don't know of one in this case.
#3
03/30/2008 (12:43 pm)
There's no leak.
If you place a breakpoint before the datablocks definition, and you go step by step you will see the memory go up as you go trough the datablocks.
However it won't go down when you make the deletes, right after the datablock creations.
Doens't work the way i was doing it, and doens't work in the way Brian suggested either.
#4
03/30/2008 (1:20 pm)
Torque never frees memory back to the operating system until you end the executable. Instead, it uses what is called a "watermark" memory management system to keep track of memory that has been handed over by the OS, and hands it out to various Torque objects as needed. When an object is deleted within Torque, it hands the memory back to the memory manager, which marks it as available for the next request within the application.

The primary reason Torque works this way is because requesting and freeing memory between the application and the operating system is one of the most expensive (performance wise) things you can ever do, but simply marking blocks of memory (once they have been allocated by the OS) as "used" or "free" is very cheap, performance wise.
#5
03/30/2008 (2:04 pm)
How interesting! Thanks Stephen, I've learnt something new today.