[Crash] Help! I don't know what causes memory leak here.

Level 2
Joined
Sep 1, 2024
Messages
8
Trigger text:



  • Periodically forcing units to pick up nearby items
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • -------- The AI doesn't take advantage of the added ability of non-hero unit to use items. Therefore, this trigger is necessary to force computer-controlled units to pick the items up. --------
      • Item - Pick every item in PlayableMapArea and do (Actions)
        • Loop - Actions
          • Set CurrentItem = (Picked item)
          • Set CurrentItemLocation = (Position of CurrentItem)
          • Player Group - Pick every player in AllComputerPlayer and do (Actions)
            • Loop - Actions
              • Set CurrentPlayer = (Picked player)
              • Set CurrentUnitGroup = (Units within 500.00 of CurrentItemLocation)
              • -------- If there is a hero with a spare item slot, the computer AI should automatically order that hero to pick up items on the ground, no needs to interfere --------
              • -------- We prefer non-interference because interference cause the unit to acts stupid in combat situation: It would be torn between the AI's order to fight and this trigger's order to pick up item, resulting in a useless unit. --------
              • Set HeroWithSpareItemSlotIsNearby = False
              • -------- Remove unqualified units from CurrentUnitGroup. And if a qualified unit is found to be a hero with spare item slot, set the corresponding boolean variable to True. --------
              • Unit Group - Pick every unit in CurrentUnitGroup and do (Actions)
                • Loop - Actions
                  • Set CurrentUnit = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Number of items carried by CurrentUnit) Equal to (Size of inventory for CurrentUnit)
                          • (Owner of CurrentUnit) Not equal to CurrentPlayer
                    • Then - Actions
                      • Unit Group - Remove CurrentUnit from CurrentUnitGroup
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (CurrentUnit is A Hero) Equal to True
                        • Then - Actions
                          • Set HeroWithSpareItemSlotIsNearby = True
                        • Else - Actions
                  • Set CurrentUnit = No unit
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • HeroWithSpareItemSlotIsNearby Equal to False
                • Then - Actions
                  • Unit Group - Pick every unit in CurrentUnitGroup and do (Actions)
                    • Loop - Actions
                      • Unit - Order (Picked unit) to Right-Click CurrentItem
                • Else - Actions
              • Set CurrentPlayer = Neutral Extra
              • Custom script: call DestroyGroup(udg_CurrentUnitGroup)
              • Set HeroWithSpareItemSlotIsNearby = False
          • Set CurrentItem = No item
          • Custom script: call RemoveLocation(udg_CurrentItemLocation)

AllComputerPlayer and PlayableMapArea is a "static" variable that is initialized once:

  • Initialize Objects
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set AllComputerPlayer = (All players controlled by a Computer player)
      • Set PlayableMapArea = (Playable map area)
      • Custom script: call DestroyTrigger(GetTriggeringTrigger())
Edit: Removed Custom script: set bj_wantDestroyGroup = true.

UPDATE: It seems that it was the event itself that leaks. I tested by disabling the above trigger and create a new one:

  • Periodically doing nothing
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • -------- do nothing --------
The trigger above does nothing, but memory usage still increases by hundreds of MB during game time.
 
Last edited:
Level 24
Joined
Feb 27, 2019
Messages
833
Custom script: set bj_wantDestroyGroup = true should be put before using a unit group to tell the game to destroy the next unit group after its used. In your trigger you use the script but then pick every item on the map which creates a group for each item. In conjunction to that you pick every player in the game which increases the amount of groups created. Only one and the first group being used is destroyed. In essence the Custom script: set bj_wantDestroyGroup = true should be placed before a unit group is used to make it be destroyed correctly.

EDIT: bj_wantDestroyGroup is generally used for unit groups that are not set to variables. If you set the unit group to a variable you should destroy it manually with call DestroyGroup(udg_variablename)
 
Level 2
Joined
Sep 1, 2024
Messages
8
Custom script: set bj_wantDestroyGroup = true should be put before using a unit group to tell the game to destroy the next unit group after its used. In your trigger you use the script but then pick every item on the map which creates a group for each item. In conjunction to that you pick every player in the game which increases the amount of groups created. Only one and the first group being used is destroyed. In essence the Custom script: set bj_wantDestroyGroup = true should be placed before a unit group is used to make it be destroyed correctly.

EDIT: bj_wantDestroyGroup is generally used for unit groups that are not set to variables. If you set the unit group to a variable you should destroy it manually with call DestroyGroup(udg_variablename)

I do have Custom script: call DestroyGroup(udg_CurrentUnitGroup) at the end of each loop. Either it's somehow not effective or there are other things that leak.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
I do have Custom script: call DestroyGroup(udg_CurrentUnitGroup) at the end of each loop. Either it's somehow not effective or there are other things that leak.
This trigger doesn't need to run 100 times per second. Id' change the interval to 1.00 second.

Anyway, the current trigger doesn't have any memory leaks, at least the kind that you can control.

This COULD leak though:
  • Item - Pick every item in PlayableMapArea and do (Actions)
 
Level 2
Joined
Sep 1, 2024
Messages
8
This COULD leak though:
  • item.gif
    Item - Pick every item in PlayableMapArea and do (Actions)

Do you have a suggestion to prevent this leak?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
How to select an item that is dropped by a creep? I searched for all the item related functions in A unit dies event, none of them works.
I think you would need to trigger the item drops yourself. Again, no idea if it's even necessary.

Unit dies -> Create item at it's position -> Set variable Item_Count = (Item_Count + 1) -> Set variable Item_Array[Item_Count] = (Last created item)
 
Top