Potential memory leak in objects
by Erik Madison · in Torque Game Engine · 10/06/2004 (12:09 pm) · 5 replies
I don't fully understand how memory is allocated/used in scripts, so this may not be a real problem. Thus, I'm not posting in 'bugs'. Please comment if you know anything :)
I'm working with objects; picking up, throwing/dropping, mounting/unmounting. When an object is mounted, the code basically searches its list of known images, and loads the one matching the item. The item is never deleted. When you later remove the image due to throwing or dropping the item, you create a new item, completely ignoring the data you've been carrying around. I assume creating a new item allocates memory?
Although my implementation is not stock, these basic functions are from the stock code in starter.fps
If I'm right, shouldn't the reverse function UnmountImage do the true reverse? Search the list of known items, and find one that matches %image.item, returning this data as the new item...
Hopefully theres at least one person left who's not too busy drinking Oregon beer to post :)
I'm working with objects; picking up, throwing/dropping, mounting/unmounting. When an object is mounted, the code basically searches its list of known images, and loads the one matching the item. The item is never deleted. When you later remove the image due to throwing or dropping the item, you create a new item, completely ignoring the data you've been carrying around. I assume creating a new item allocates memory?
Although my implementation is not stock, these basic functions are from the stock code in starter.fps
If I'm right, shouldn't the reverse function UnmountImage do the true reverse? Search the list of known items, and find one that matches %image.item, returning this data as the new item...
Hopefully theres at least one person left who's not too busy drinking Oregon beer to post :)
About the author
#2
I found this when I decided it would be proper to delete the item once its been converted to an image and mounted. This caused the image to no longer exist. So I stepped through the image code and realized there really wasn't much difference in items and images. I did not however, try deleting the object _after_ it was unmounted and after Ive created a new one.
10/06/2004 (12:48 pm)
I'm not yet refering to remounting, and excessive mounting of the same data wouldn't cause any problems I can think of. Its the unmounting AND discarding that appears to be a problem. The imagedata you once held is still there (AFAIK), its simply no longer attached to you.I found this when I decided it would be proper to delete the item once its been converted to an image and mounted. This caused the image to no longer exist. So I stepped through the image code and realized there really wasn't much difference in items and images. I did not however, try deleting the object _after_ it was unmounted and after Ive created a new one.
#3
to summarize:
items can exist by themselves in the gameworld as an object
images must always be attached to an object
items' appearance/behavior is determined by its datablock.
images appearance/behavior also determined by datablock
items can have variables (dynamic fields as they are called) assigned to them
images can not
images can not be instantiated as objects
the only way to "create" an image is to attach it to seomthing using mountimage, once the image unmounts it no longer exists ingame
when you pick up a pickuppable item, the item IS deleted.
items are generic mobile game objects
images are meshes attached to objects which is used for various purposes (weapons, etc)
images do not need to be deleted since they are really never created
image datablocks are created on game start
all datablocks are created on game start
10/07/2004 (8:36 pm)
If i remember correctly its all automatic. Picked up items are automatically dealt with. the imagedata is still there because its a datablock. all datablocks are omnipresent once you connect to a server(or start one) and will stay there forever. Images are not technically "objects", you cant set variables in them, all you can really do is mount and unmount them. the actual image "object" does not exist script wise, but the image datablock exists all the time. Usually you can have an upward of 2040 datablocks loaded in a game at a time.to summarize:
items can exist by themselves in the gameworld as an object
images must always be attached to an object
items' appearance/behavior is determined by its datablock.
images appearance/behavior also determined by datablock
items can have variables (dynamic fields as they are called) assigned to them
images can not
images can not be instantiated as objects
the only way to "create" an image is to attach it to seomthing using mountimage, once the image unmounts it no longer exists ingame
when you pick up a pickuppable item, the item IS deleted.
items are generic mobile game objects
images are meshes attached to objects which is used for various purposes (weapons, etc)
images do not need to be deleted since they are really never created
image datablocks are created on game start
all datablocks are created on game start
#4
Yes, you are creating a new instance of the object for inclusion in the game world. You then need to add it.
Lastly you can schedule it for deletion.
10/07/2004 (9:33 pm)
:I assume creating a new item allocates memory?Yes, you are creating a new instance of the object for inclusion in the game world. You then need to add it.
Lastly you can schedule it for deletion.
#5
@Yiding
Thats a great summary! Even the parts I already understood are clearer now seeing it listed like that.
Now, I hit a new problem. If images can't hold variable data, I need to rethink how I handle ammo clips and bagged contents. I suppose Ill have to copy object variables to player variables and back to object variables as items are picked up/dropped.
10/08/2004 (1:29 am)
Thanks. I did find where the object gets deleted. I got confused since I was watching pre loaded items given to the player, which are never created since they are images right from the start. Once I began following mission loaded items, which are created as items, then I found the deletion.@Yiding
Thats a great summary! Even the parts I already understood are clearer now seeing it listed like that.
Now, I hit a new problem. If images can't hold variable data, I need to rethink how I handle ammo clips and bagged contents. I suppose Ill have to copy object variables to player variables and back to object variables as items are picked up/dropped.
Torque Owner Stefan Lundmark
Have you made a function that mounts and mounts and mounts to see if there are any differences in memory for the .exe?