AMAI icon indicating copy to clipboard operation
AMAI copied to clipboard

Various local handle variables not being cleaned up to avoid resource leaks

Open jzy-chitong56 opened this issue 2 years ago • 7 comments

like this

function SelectUnittype takes group g, unittype typ, boolean is_of_type returns group
     local unit u = null
     local group rg = CreateGroup()
     loop
       set u = FirstOfGroup(g)
       exitwhen u == null
       if IsUnitType(u, typ) == is_of_type then
          call GroupAddUnit(rg, u ) 
       endif
       call GroupRemoveUnit(g, u )
     endloop
     call DestroyGroup(g)
     return rg
endfunction

takes group g local group rg returns group rg

here call DestroyGroup(g), so g is excretion success in SelectUnittype then in function XXXX there call SelectUnittype , if DestroyGroup(g) again , the g != rg , and Destroy fail? excretion fail?


Same question Exist in Location like

function GetSubtractionLoc_dd takes location l1, location l2 returns location
  local real locX = GetLocationX(l1) - GetLocationX(l2)
  local real locY = GetLocationY(l1) - GetLocationY(l2)  
	call RemoveLocation(l1)
    call RemoveLocation(l2)
  return Location(locX, locY)
endfunction

returns is locX and locY

but we cannot know location l1 and location l2 will it continue to be used , so we cannot call RemoveLocation(l1) ,set l1 = null


and this , know location l1 and location l2 no longer needed ,so RemoveLocation, but call RemoveLocation(l2) , why have not set l2 = null ? intended?

function GetSubtractionLoc_dd takes location l1, location l2 returns location
  local real locX = GetLocationX(l1) - GetLocationX(l2)
  local real locY = GetLocationY(l1) - GetLocationY(l2)  
	call RemoveLocation(l1)
    call RemoveLocation(l2)
  return Location(locX, locY)
endfunction
function GetSubtractionLoc_kd takes location l1, location l2 returns location
  local real locX = GetLocationX(l1) - GetLocationX(l2)
  local real locY = GetLocationY(l1) - GetLocationY(l2)  
    call RemoveLocation(l2)
  return Location(locX, locY)
endfunction

last , in Blizzard.eai

  local button b = GetClickedButton()
  local trigger t = CreateTrigger()

so many ,and no excretion


I'm afraid that why the game will stuck

jzy-chitong56 avatar Aug 27 '22 16:08 jzy-chitong56

The method ends with _dd or _kk or _kd which means _dd Destroy both locations _kd Keep first location, destroy second

have to use the method based on what is required in the calling logic.

You are correct we are missing reset of local handle variables to null so there are leaks ongoing. Triggers and dialogs are not cleaned up at all in the commander.

Alot of locations and groups were cleaned up a long time ago using a tool to detect the leaks automatically as it ran. That tool no longer works though.

SMUnlimited avatar Sep 06 '22 16:09 SMUnlimited

The method ends with _dd or _kk or _kd which means _dd Destroy both locations _kd Keep first location, destroy second

have to use the method based on what is required in the calling logic.

You are correct we are missing reset of local handle variables to null so there are leaks ongoing. Triggers and dialogs are not cleaned up at all in the commander.

Alot of locations and groups were cleaned up a long time ago using a tool to detect the leaks automatically as it ran. That tool no longer works though.

24 player map still caton , even collapse

jzy-chitong56 avatar Sep 09 '22 09:09 jzy-chitong56

The method ends with _dd or _kk or _kd which means _dd Destroy both locations _kd Keep first location, destroy second have to use the method based on what is required in the calling logic. You are correct we are missing reset of local handle variables to null so there are leaks ongoing. Triggers and dialogs are not cleaned up at all in the commander. Alot of locations and groups were cleaned up a long time ago using a tool to detect the leaks automatically as it ran. That tool no longer works though.

24 player map still caton , even collapse

Well, I'm new here at AMAI. However, I think the script supports up to 12 players (at least that's what I could read in the code). @SMUnlimited can confirm this for you.

paulo101977 avatar Sep 09 '22 12:09 paulo101977

It works with 24 players, but it does put more stress on the system hence why memory leak fixes are more important.

It hasn't been unplayable for me though.

SMUnlimited avatar Sep 11 '22 13:09 SMUnlimited

@SMUnlimited
I try to excretion some local variables , for reference only but you must very look out I change universal_peon_assignment , i want to at the beginning of the game, don't let all the peon go gold , have 1 go wood , 4 go gold , but on 24 player map , the game stuck , the game start is less than five minutes (I have compared the documents, and like change this code paragraph , the game can go on )

call HarvestGold(T,ver_optimal_gold - 1)
	call HarvestWood(0,pwh)
 call HarvestGold(T,1)
 call HarvestWood(0,swh)

https://github.com/jzy-chitong56/amai-map/blob/main/common.eai

jzy-chitong56 avatar Sep 11 '22 17:09 jzy-chitong56

@SMUnlimited I rearrange excretion, but it still gets stuck , but maybe will Better

and the code include new towerrush,have new Variables, so you maybe just can comparison,

https://github.com/jzy-chitong56/amai-map/blob/main/common.ai

jzy-chitong56 avatar Sep 18 '22 17:09 jzy-chitong56

@SMUnlimited please try this Version https://github.com/jzy-chitong56/amai-map/tree/main/Scripts at the beginning of the game, Although when reporting no "27" appear , the game have some stuck (I still haven't found the rest of the excretion. Maybe I really forever can't found, but i will keep found ,I suspect The two neutral store check systems run at the same time. Because the unit group I use is the same global variable, when the two systems call at the same time, there will be a problem) buy game normal most of the time if you allow ,i will commit branch, after more testing (I use a lot of global variables, very rigid , consistent with AMAI philosophy)

jzy-chitong56 avatar Sep 25 '22 17:09 jzy-chitong56

Various of jzy-chitong56 optimizations merged into master

SMUnlimited avatar Oct 15 '23 19:10 SMUnlimited