• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Memory Leak fix

Status
Not open for further replies.
Level 2
Joined
Jul 9, 2011
Messages
12
Hey guys it seems like I'm missing one leak in this trigger..
  • ggmode
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set RandomMarine_Group = (Random unit from (Units in (Playable map area) owned by (Random player from (All players controlled by a User player))))
      • Set Position_Point = (Position of RandomMarine_Group)
      • Set Temp_Point = (Random point in Region 027 <gen>)
      • Region - Center Region 027 <gen> on Position_Point
      • Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Position_Point)
Its supposed to set a region to a random unit controlled by a user (in this case it would be one of the marines people use) and then it spawns a random unit type (i have array made in a different trigger) and then it removes the variables.. I ran it through leak checker and its saying that there is a leak in 'Set RandomMarine_Group = (Random unit from (Units in (Playable map area) owned by (Random player from (All players controlled by a User player)))) '

Does anyone know where it is and how to fix it? Fixing this leak is crucial because this trigger can run for quite awhile..
 
Last edited by a moderator:
Level 4
Joined
Apr 5, 2008
Messages
70
I think its the player group.
"Random player from (All players controlled by a User player)"
It's like a unitgroup for players.
 
Level 26
Joined
Mar 19, 2008
Messages
3,140
You miss unit group leak. Use trigger tags next time.
Thats for further informations.
@TheBlueOne (All players) do not leaks.

  • ggmode
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set RandomMarine_Group = (Random unit from (Units in (Playable map area) owned by (Random player from (All players controlled by a User player))))
      • Set Position_Point = (Position of RandomMarine_Group)
      • Set Temp_Point = (Random point in Region 027 <gen>)
      • Region - Center Region 027 <gen> on Position_Point
      • Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Position_Point)
      • Custom script: call DestroyGroup (udg_RandomMarine_Group)
However, if you need that group for further purposes, dont destroy it.
 
Level 2
Joined
Jul 9, 2011
Messages
12
how do i fix the leak though? sorry i wasnt more specific above, leak checker is giving this:

(Line: 6 ) (Word: 7 ) Unit Group Leak
Set RandomMarine_Group = (Random unit from (Units in (Playable map area) owned by (Random player from (All players controlled by a User player))))
Set RandomMarine_Group = (Random unit from ^Leak
(Suggested fix) Custom Script: set bj_wantDestroyGroup = true
(Suggested fix) Set RandomMarine_Group = (Random unit from (Units in (Playable map area) owned by (Random player from (All players controlled by a User player))))

I tried making a custom script with set bj_wantDestroyGroup = true and it didnt fix the leak. it didnt matter where i put it either :\
 
Level 26
Joined
Mar 19, 2008
Messages
3,140
Units in Playable area leaks. And by the way, I thought RandomMarine_Group is a group variable, but its not. It has to be unit variable because Random unit from unit gorup refers only to units, not unit groups. Sorry for missunderstanding at first post. (that '_Group' in variable was confusing -.-)

Actions:
  • Set tempG = (Units in (Playable map area) owned by (Random player from (All players controlled by a User player)))
  • Set RandomMarine_Group = (Random unit from tempG)
  • Set Position_Point = (Position of RandomMarine_Group)
  • Set Temp_Point = (Random point in Region 027 <gen>)
  • Region - Center Region 027 <gen> on Position_Point
  • Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
  • Custom script: call RemoveLocation (udg_Temp_Point)
  • Custom script: call RemoveLocation (udg_Position_Point)
  • Custom script: call DestroyGroup (udg_tempG)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
1) Create a unit group variable (I will call it tempForce).
2) Create a player group variable (I will call it tempGroup).

set tempForce = (All players controlled by a User player)
set tempGroup = (Units in (Playable map area) owned by (Random player fromtempForce)))
set randomMarine = random unit from tempGroup

Custom script: call DestroyForce(udg_tempForce)
Custom script: call DestroyGroup(udg_tempGroup)


Additionally: leak checker has flaws and sometimes doesn't know what leaks and what doesn't. I HIGHLY suggest you go learn that yourself, as it is
1) Faster: you don't have to run the program every time.
2) Easier: in case Leak Checker is wrong, you're not breaking your head over it, because then you know leak checker is wrong.

And what leaks? All player groups, unit groups, locations, special effects, (strings, cannot be fixed, but leaks in a 'different' way, so not important), aaand... well, for GUI-users, that's about it I guess. Easy, right?
Only ONE exception: "all players" does not leak. That's all. Fix the rest.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Was a bit faster :D
By the way (All players controlled by a User player) creates a leak? Its refering to player force (player group customized) or to All players (which do not leak)?
As I said: the only exception is "All Players", which does not leak.

Even this leaks:
  • Game - Display to (Player group(Player 1 (Red))) the text: message
For more information on the "All players controlled by a user player", read the JASS-script:
JASS:
function GetPlayersByMapControl takes mapcontrol whichControl returns force
    local force f = CreateForce()
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if GetPlayerController(indexPlayer) == whichControl then
            call ForceAddPlayer(f, indexPlayer)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
    endloop

    return f
endfunction
It clearly creates a new force (a player group is called "force" in JASS) here (the first action: local force f = CreateForce()).
If you do not remove that new force, it will stay in your memory (and then you have a memory leak).

While "All Players":
JASS:
function GetPlayersAll takes nothing returns force
    return bj_FORCE_ALL_PLAYERS
endfunction
It doesn't create a new force.
This is set up at the start of the map.
Removing this force is even dangerous, as you can never access "all players" again once you do so.
 
Level 2
Joined
Jul 9, 2011
Messages
12
Units in Playable area leaks. And by the way, I thought RandomMarine_Group is a group variable, but its not. It has to be unit variable because Random unit from unit gorup refers only to units, not unit groups. Sorry for missunderstanding at first post. (that '_Group' in variable was confusing -.-)

Actions:
  • Set tempG = (Units in (Playable map area) owned by (Random player from (All players controlled by a User player)))
  • Set RandomMarine_Group = (Random unit from tempG)
  • Set Position_Point = (Position of RandomMarine_Group)
  • Set Temp_Point = (Random point in Region 027 <gen>)
  • Region - Center Region 027 <gen> on Position_Point
  • Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
  • Custom script: call RemoveLocation (udg_Temp_Point)
  • Custom script: call RemoveLocation (udg_Position_Point)
  • Custom script: call DestroyGroup (udg_tempG)

Your the man! thanks a ton man it works PERFECTLY! now i just have to apply this to all my other spawner triggers. +rep!
 
Level 2
Joined
Jul 9, 2011
Messages
12
Okay so.. i may have lied.. my trigger wont work like i planned.. my trigger is this:

ggmode
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
Set TempGroup = (Units in (Playable map area) owned by (Random player from (All players controlled by a User player)))
Set RandomMarine_Group = (Random unit from TempGroup)
Set Position_Point = (Position of RandomMarine_Group)
Set Temp_Point = (Random point in Region 027 <gen>)
Region - Center Region 027 <gen> on Position_Point
Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
Custom script: call RemoveLocation (udg_Temp_Point)
Custom script: call RemoveLocation (udg_Position_Point)
Custom script: call DestroyGroup (udg_TempGroup)

instead of making a random unit from my array that i made for it, it randoms a unit then sends 1 of those any second.. any help? sorry i cant get editor tags to work
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
The trigger tags are just: [trigger] {paste trigger here} [/trigger]. I bet those tags weren't easy to make, so it's always nice to see people use them :D

And again: you missed the player group leak, as 2 people already mentioned (me and TheBlueOne).


Question: why do you set Temp_Point to a random point in region 17first and only AFTERWARD move that region? Wouldn't it be more logical the other way around?

instead of making a random unit from my array that i made for it, it randoms a unit then sends 1 of those any second.. any help?
Where do you set "RandomInt"?
What do you mean with "sends 1 of those any second"? Who is "one of those" and in which way is it different from the random unit from your array?
 
Last edited:
Level 2
Joined
Jul 9, 2011
Messages
12
Totally fixed!
  • ggmode
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set TempGroup = (Units in (Entire map) owned by (Random player from (All players controlled by a User player)))
      • Set RandomMarine_Group = (Random unit from TempGroup)
      • Set Position_Point = (Position of RandomMarine_Group)
      • Set Temp_Point = (Random point in Region 027 <gen>)
      • Set RandomInt = (Random integer number between 1 and 10)
      • Region - Center Region 027 <gen> on Position_Point
      • Unit - Create 1 RandomSpawnArray[RandomInt] for Player 12 (Brown) at Temp_Point facing Default building facing degrees
      • Custom script: call RemoveLocation (udg_Temp_Point)
      • Custom script: call RemoveLocation (udg_Position_Point)
      • Custom script: call DestroyGroup (udg_TempGroup)
Thanks everyone for the awesome feedback! Couldnt have fixed without it :) tyty
 
Status
Not open for further replies.
Top