HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

about leaks

02-24-2007, 04:23 AM#1
midiway
I was reading about memory leaks and found it: Things that are not handles are integers, reals, booleans; these are just numbers. They are stored in their variables and are erased the moment the variable is set to a new value.

So, by the same way, if I have a variable wich, for example, is storing a point, when I use it again seting a new point, won't erase his content to store this new value? Or I need to use Custom script: call RemoveLocation( udg_tempPoint ) every time after it has serverd it`s purpose?

My english isn't very good yet ...
02-24-2007, 04:44 AM#2
Ammorth
Yes, you must use the proper functions for each handle to remove them. You can either use that before you use the variable again, or directly after (but cannot have any waits between using and cleaning).
02-24-2007, 04:55 AM#3
Krysho
When you create a point (and most things handle-based), the point itself is in the game, stored in memory. If you set a variable to that point (location), then the variable itself only references to the point. Nullifying the variable or setting it to something else is only half the work then.

You can think of it in terms of units if it helps, since it's more common. Set a variable to a unit, then set that variable to a different unit. The unit in the game still exists, even though you set the variable to something else, yes? Same thing with points. When you're done, you have to remove it from the game AND nullify the variable or set the variable to something else.

Simply (or not so simply) put, the variable doesn't store the actual contents of the handle (the very name handle is a good descriptor here, if you're from another programming background), just the information necessary to get to the actual contents.

This is how I've come to see it, anyway, anyone feel free to correct me if I'm wrong.
02-24-2007, 05:23 AM#4
midiway
Compare this 2 examples:

Trigger:
Actions
Set TempPoint = (Center of RegionX)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )
Set TempPoint = (Center of RegionY)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )
Set TempPoint = (Center of RegionZ)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )
Trigger:
Actions
Set TempPoint = (Center of RegionX)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Set TempPoint = (Center of RegionY)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Set TempPoint = (Center of RegionZ)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )

Will each example erase every reference to the points?
02-24-2007, 05:31 AM#5
Ammorth
No, the first one is correct, the second one will leak 2 points, (center of X and Center of Y).

but, you can do something like this:

Trigger:
Some Trigger
Collapse Events
Time - Every 1 second of game-time
Conditions
Collapse Actions
Custom script: call RemoveLocation( udg_TempPoint )
Set TempPoint = (Center of RegionX)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )
Set TempPoint = (Center of RegionY)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
Custom script: call RemoveLocation( udg_TempPoint )
Set TempPoint = (Center of RegionZ)
Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing 100.00 degrees
This will still not leak, because you are always clearing the handle before you use the variable again. This is better if you have many systems that will be using your variable, because it makes sure that the variable is referencing a correct handle at all times. If your code is clean and you have no crazy systems, you can destroy your points right after you use them. It's basically just a preference.