Question About Memory Leaks

crabbb622

New Member
Reaction score
9
If you make a temporary unit group why must you delete it after you're done? The variable would still be kept track of and if you wanted to use it again, you could just overwrite it?
 

simonake

New Member
Reaction score
72
If you don't plan to use a group anymore, destroy it. If you want to create a new group with the same variable (wich is what GUI does), you must destroy it or the game will remember it till end of game, causing lot of lag. If you want to use it sereval time and later in the game, don't destroy it.
 

elmstfreddie

The Finglonger
Reaction score
203
Keyword: Temporarey.
If you were to re-use the variable then you wouldn't need to delete it.

Normally though, people make groups without realising. Using functions like "units within x distance"... "every unit under these conditions"... kind of thinsg. It creates groups that never are remoevd. That's why you set a variable to it so it CAN be removed.

Ehm, so if you wanted to the same 12 units all game you'd never delete that variable.

I'm not really sure if that was your question though?
If you're asking where the data goes that the variable previously had when it's rewritten, then I presume it's removed, but you can't presume anything with WE.. :p
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Globals can be overwrited. Actually destroy group is unsafe. The safest method is recycle it by using Group Clear
 

crabbb622

New Member
Reaction score
9
Ok so let's say i pick up some units and put it into tempGroup. So then i can say Pick up every unit in tempGroup and do crap, which will not cause a memory leak (allegedly...). Word on the street is that you use custom script to burn that variable to the ground and never see it again. And when you want another temporary group, you store the new units into the group.

What I'm asking is that is it necessary to manually remove the variable, since overwriting it would naturally destroy it. Or rather, doesn't tempGroup always point to the same exact spot in memory throughout the game?

Edit: And yea, all i need is to verify kingkingyyk3's technique.
 

Tom Jones

N/A
Reaction score
437
Ok so let's say i pick up some units and put it into tempGroup. So then i can say Pick up every unit in tempGroup and do crap, which will not cause a memory leak (allegedly...). Word on the street is that you use custom script to burn that variable to the ground and never see it again. And when you want another temporary group, you store the new units into the group.

What I'm asking is that is it necessary to manually remove the variable, since overwriting it would naturally destroy it. Or rather, doesn't tempGroup always point to the same exact spot in memory throughout the game?

Edit: And yea, all i need is to verify kingkingyyk3's technique.
To understand leaks we'll first have to clarify some stuff:

The variable types that leak are different from the ones that don't. Variable types that don't leak uses their space in the memory to hold a direct value, whereas variable types that leaks uses their space in the memory to point to an object in the memory.

Overwriting a variable of a type that points somewhere will only result in a new pointer. The object in the memory that the variable used to point to is still allocated in the memory, and since we overwritten the variable with a new pointer we have no chance of destroying said object. We've created a leak.

That's why it's necassary to clean objects from the memory before assigning a new pointer to the variable.

As kingkingyyk3 said you can also deal with this by using a static object. Because we never destroy the object or assign a new pointer to the variable, we'll reference the same object throughout the entire game. However DestroyGroup(...) is plenty safe.
 

crabbb622

New Member
Reaction score
9
Overwriting a variable of a type that points somewhere will only result in a new pointer. The object in the memory that the variable used to point to is still allocated in the memory, and since we overwritten the variable with a new pointer we have no chance of destroying said object. We've created a leak.

As I understood it, a certain amount of memory is given to a pre-specified variable and that block of memory would hold a changable value. Are you saying that every time a variable is stored, it goes to a different place (or that changing the value of the variable actually means pointing to a different loacation in memory)?
 

Tom Jones

N/A
Reaction score
437
As I understood it, a certain amount of memory is given to a pre-specified variable* and that block of memory would hold a changable value. Are you saying that every time a variable is stored, it goes to a different place (or that changing the value of the variable actually means pointing to a different loacation in memory)?**
*Correct.
**Correct, but only for variable types that leaks.
 

crabbb622

New Member
Reaction score
9
So would this work:

Trigger:
  • End Copy Copy
    • Events
    • Conditions
    • Actions
      • Set tempGroup = (Units in (Playable map area))
      • Unit - Explode (Random unit from tempGroup)
      • Unit Group - Pick every unit in tempGroup and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Move To (Random point in (Playable map area))


And I wouldn't even have to clean that up to reuse tempGroup for something else?
 

crabbb622

New Member
Reaction score
9
Sorry, what i meant to ask is: Isn't removing it from memory unnecessary because if you're just going to leave the group untouched, but still existing, it won't cause more memory to be taken up.
 

Dameon

"All the power in the world resides in the eyes"
Reaction score
127
Because in the future (multiplayer game) it will generate lots of lag if you do not clean up your leaks.

Read this if you want to learn more about Memory Leaks and Custom Script Guide;

http://www.thehelper.net/forums/showthread.php?t=27219&highlight=leaks

This is just not true, a lot of people have become leak nazi's but they overstate things a bit, you can get over 500K leaks with no visable lag, you wqill notice the leaks when the game is over and it takes forever to close the map, but it is only certain types of leaks that will cause lag, and even then not always.

To put this simple if your map is going to be played and won in under 20 to 25 minutes don't bother removeing leaks, you wont notice them. 25 to 30 minutes just remove the constant leaks, any thing more then 35 then you will want to remove as many as you can.
 

SpaceBar

New Member
Reaction score
16
This is just not true, a lot of people have become leak nazi's but they overstate things a bit, you can get over 500K leaks with no visable lag, you wqill notice the leaks when the game is over and it takes forever to close the map, but it is only certain types of leaks that will cause lag, and even then not always.

To put this simple if your map is going to be played and won in under 20 to 25 minutes don't bother removeing leaks, you wont notice them. 25 to 30 minutes just remove the constant leaks, any thing more then 35 then you will want to remove as many as you can.

True, but in most cases, it's always best to remove most if not all the leaks anyway
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top