Let's talk about memory leaks

crabbb622

New Member
Reaction score
9
Code:
        Set Temp_Group = (Units in (Playable map area))
        Unit Group - Pick every unit in Temp_Group and do (Actions)
            Loop - Actions
                Unit - Kill (Picked unit)
        Custom script:   call DestroyGroup (udg_Temp_Group)

I've always been skeptical of this last line (destroying the variable), although you guys are experienced i guess so it must be right.
But...
Why wouldn't the variable clean itself up on being overwritten. I mean, I would understand if it was a different variable being used each time, but aren't we using the same block of memory each time here?

Can someone explain on a low-level perspective of why this is? It's not in the tutorial because I suppose you don't really need to know, but it's really bugging me.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
890
The variable is just a pointer to where the data is stored. Thus, if you overwrite the pointer, you don't get rid of the actual data. So it stacks up in memory. A leak. To get rid of the actual data, that function is what you use.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
I'm pretty sure it actually creates a new group in the memory each time.
So everytime you run it without the removal, it leaks a group.
 

Azlier

Old World Ghost
Reaction score
461
The variable is merely pointing to an object. If you reset the variable, you lose the object in memory. You have to destroy the object before you lose it by resetting the variable.

EDIT: How did two people post within 5 seconds?
 
Reaction score
341

Azlier

Old World Ghost
Reaction score
461
Then what are we supposed to say? Doohickey? Thingamabob?
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Well that's just hick :p .

Think back to when you were (Completely) new though;
You probably got confused by things like that ;) .
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
890
Pointer? Name? Label? Title? Reference? Id?
The point is that it isn't the actual data, but merely a name for it. If all you do is make the name reference something new, you haven't gotten rid of the initial data, and since there is no way to name it now, it's gone forever, lost in the depths of RAM....
 

Azlier

Old World Ghost
Reaction score
461
There is only one way to clean objects you never reference by pointing to them via variable. It is a truly evil hack. Something much more mysterious than this.
 

Pyroflame

New Member
Reaction score
4
Saying pointer is fine... "Pointer" "Point" "Pointing to something" how could you go wrong with using that word. Ghan_04 had the best defination.
 

crabbb622

New Member
Reaction score
9
guys...low-level doesn't mean five year old. it means computer-level concepts, like assembly programming, if you've ever heard of that. lawl.

anyway, so from what i understand the computer allocates memory every time you set a value to a variable at ANY time and when you overwrite it, it never tells itself that that memory is free now?
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
890
Whenever you create an object of some type, it allocates the memory. CreateGroup(), etc. all do this. But once you shift the pointer away from that allocated memory space without clearing it and go around creating more allocated spaces, you leak.
 

Azlier

Old World Ghost
Reaction score
461
Jass doesn't have an automagic garbage collector.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
890
> Jass doesn't have an automagic garbage collector.

Yet. :p
We can always hope for SC2.... Even though I have no idea if they will use JASS there.
 

crabbb622

New Member
Reaction score
9
> Jass doesn't have an automagic garbage collector.

Yet. :p
We can always hope for SC2.... Even though I have no idea if they will use JASS there.

haha, i have been wondering what kind of editor SC2 will have. waiting for it :O

Anyways, thanks guys, i understand it now
I won't have to stay up all night thinking about it
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top