• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Point Leaks

Status
Not open for further replies.
Level 12
Joined
May 20, 2009
Messages
822
So, I'm not exactly sure how this works. If I do,

  • Set MS_MoverPoint[MS_Index[1]] = (Position of MS_Unit[MS_Index[1]])
And when I go to do

JASS:
call RemoveLocation( udg_MS_MoverPoint[udg_MS_Index[1]] )

MS_MoverPoint is a reference to the information in the first line, correct? So doing RemoveLocation is removing what the variable is referencing, and thus this wouldn't be a leak? And also any reference to MS_MoverPoint wouldn't cause a leak either?
 
Yep. You can think of each index as being its own variable. Let's say that this is what the state of the array is:

MS_MoverPoint[1] -> Location #1
MS_MoverPoint[2] -> Location #2
MS_MoverPoint[3] -> <empty> (nothing has been assigned to this slot)

If you run the code you have above, it'll now look like:

MS_MoverPoint[1] -> <removed>
MS_MoverPoint[2] -> Location #2
MS_MoverPoint[3] -> <empty>

So MS_MoverPoint[1] has been handled properly. MS_MoverPoint[2] (in our hypothetical case), still points to a location though. When you are done with that, you'll want to remove it. We never assigned MS_MoverPoint[3], so we don't have to worry about removing it.
 
Level 12
Joined
May 20, 2009
Messages
822
So I'm not mistaken then? The point itself isn't being stored in the variable, the variable is just referencing the point? Which is why using Position Of Unit without storing it in a point causes a leak, because you create a point with nothing referencing it so you can't actually remove it?
 

EdgeOfChaos

E

EdgeOfChaos

Your understanding is correct. Point variables contain a reference. Somewhere in memory, a point is created at some location, like Location@034, then the variable stores that path. Position of Unit creates a point, then nothing is set to it, so the pointer is lost but still takes up memory space. RemoveLocation follows the path of the reference variable, and then destroys the point it finds at that path. It should actually be called DestroyLocation. That's what happens in the code posted in the OP - the point found by the reference in the array at spot 1 is destroyed from memory.

You seem to already have an understanding of this, so you might find it useful to draw memory diagrams if you get confused, for example this one I once drew to show a unit, a location, and a location leak: https://drive.google.com/file/d/0BxRU5OXqgk5UaDI4WWQtM0pPYWM/view?usp=sharing
 
Status
Not open for further replies.
Top