Thinking about boolexprs

Magoiche

Member
Reaction score
20
Once upon a time someone told me that in enum functions a null boolexpr leak.
But i was tinking about that and noticed that when i use some BJ that call a enum function my boolexpr isn't null, so i belive it won't leak. Right?
Or because a BJ it will leak and i have to inline/make it my own function?

Example:

JASS:
    local group PossibleTargets = GetUnitsInRangeOfLocMatching(500.00, CasterLoc, Condition( function TargetAndGroupConditions ) )


Thanks =]
 

Builder Bob

Live free or don't
Reaction score
249

Romek

Super Moderator
Reaction score
963
Tinking -> Thinking. :p

I don't quite understand what you're saying.
Null boolexprs do leak. Using your own Filter() or Condition() will prevent that.
The filter can be something as simple as:
JASS:
function True takes nothing returns boolean
return true
endfunction


BJ's which use null leak. ;)
 

Romek

Super Moderator
Reaction score
963
> I'm beginning to see where those rumors are coming from..
Hmm, I never did any testing myself, but I assumed it was true seeing as a lot of good coders agreed with it.
I just did some testing with handle count, and by checking memory usage by Wc3.
Handle count isn't increased no matter when null is used. (Well, tested with events, and GroupEnum. Events increases handle count by 1 each time called. Obviously because the returned event is a handle).
However, memory usage by wc3 does seem to steadily increase when using null for GroupEnum. It doesn't increase at all compared to 'null' when using Filter(function True).

I'll do some more testing and retesting with different functions and stuff. Hopefully I'll be able to come to a safe conclusion.
 

saw792

Is known to say things. That is all.
Reaction score
280
I also tested this after brazenly declaring all null boolexprs leak myself. My results also show no difference in handle count between an inlined AnyUnitEventBJ() using null and one using a true conditionfunc (which was created for both tests, but only used in one).
 

Viikuna

No Marlo no game.
Reaction score
265
Yea, I too believe these things when I hear them.

I guess we just need more testing and less talk without testing. ( Too bad Im usually too lazy to test these things. :D )
 

Romek

Super Moderator
Reaction score
963
Well, the handle count doesn't increase (Then again, why would it? No=ones creating handles). But the mem. usage does.
I tested with a 0.01 second timer. First using null, then using Filter(function True).
The memory usage goes up and down occasionally for both tests. But with null, there is generally a bigger increase.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Well, the handle count doesn't increase (Then again, why would it? No=ones creating handles). But the mem. usage does.
I tested with a 0.01 second timer. First using null, then using Filter(function True).
The memory usage goes up and down occasionally for both tests. But with null, there is generally a bigger increase.

Post your code.
 

Romek

Super Moderator
Reaction score
963
Post your code.
JASS:
scope test initializer Init

    globals
        group G = CreateGroup()
    endglobals
    
    function Tr takes nothing returns boolean
        return true
    endfunction

    function Exp takes nothing returns nothing
        call GroupEnumUnitsInRange(G, 0., 0., 0., null)
       // call GroupEnumUnitsInRange(G, 0., 0., 0., Filter(function Tr))
        call BJDebugMsg(".")
    endfunction

    function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.01, true, function Exp)
    endfunction

endscope


Try it yourself. I'm still not entirely convinced though. The memory usage could be going up for other reasons. And it goes up and down for both the filter and null either way. :p

Retested twice. It does seem to go up much more rapidly with null.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Hmm you don't clean the group :p
Also just comment BJDebugMsg if you didn't.

And for group it leaks it is sure 100 %, if you really want to test, do it with other boolexpr like TriggerRegister.
 

Romek

Super Moderator
Reaction score
963
> Hmm you don't clean the group :p
No need. GroupEnum overwrites the group.
Why would I need to anyway?

The message is uncommented for both tests for me. So it's not the cause of one of them rising faster than the other. :)

Edit: Without the message, the difference is even more noticeable. with Filter(function TR), the memory usage went up by 16 over about 10 seconds. With null it went up by about 200.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
> Hmm you don't clean the group :p
No need. GroupEnum overwrites the group.
Why would I need to anyway?

The message is uncommented for both tests for me. So it's not the cause of one of them rising faster than the other. :)

Edit: Without the message, the difference is even more noticeable. with Filter(function TR), the memory usage went up by 16 over about 10 seconds. With null it went up by about 200.

Yes you're right for the GroupClear.
But i've tested and the memory doesn't go up for me with the true filter, but it leaks with the null boolexpr, but i don't display strings, and so didn't test if the handles go up or not.
 

Romek

Super Moderator
Reaction score
963
> But i've tested and the memory doesn't go up for me with the true filter, but it leaks with the null boolexpr

Same results as I got.

> and so didn't test if the handles go up or not.
Put this in your code somewhere. The HandleCounter I used. :)
JASS:
globals
        leaderboard udg_HandleBoard
endglobals

function HandleCounter_L2I takes location P returns integer
        return P
        return 0
endfunction

function HandleCounter_Update takes nothing returns nothing
        local integer i = 0
        local integer id
        local location array P
        local real result=0
        loop
                exitwhen i >= 50
                set i = i + 1
                set P<i> = Location(0,0)
                set id = HandleCounter_L2I(P<i>)
                set result = result + (id-0x100000)
        endloop
        set result = result/i-i/2
        loop
                call RemoveLocation(P<i>)
                set P<i> = null
                exitwhen i &lt;= 1
                set i = i - 1
        endloop
        call LeaderboardSetItemValue(udg_HandleBoard,0,R2I(result))
endfunction

function HandleCounter_Actions takes nothing returns nothing
        set udg_HandleBoard = CreateLeaderboard()
        call LeaderboardSetLabel(udg_HandleBoard, &quot;Handle Counter&quot;)
        call PlayerSetLeaderboard(GetLocalPlayer(),udg_HandleBoard)
        call LeaderboardDisplay(udg_HandleBoard,true)
        call LeaderboardAddItem(udg_HandleBoard,&quot;Handles&quot;,0,Player(0))
        call LeaderboardSetSizeByItemCount(udg_HandleBoard,1)
        call HandleCounter_Update()
        call TimerStart(GetExpiredTimer(),0.05,true,function HandleCounter_Update)
endfunction

//===========================================================================
function InitTrig_HandleCounter takes nothing returns nothing
        call TimerStart(CreateTimer(),0,false,function HandleCounter_Actions)
endfunction

</i></i></i></i>


I guess we can come to a conclusion that 'null boolexprs' actually do leak?
 

saw792

Is known to say things. That is all.
Reaction score
280
We need some way to check memory allocation or something, or at least find out how null boolexprs actually do leak (if they do). Hmm sortof stating the obvious here aren't I...
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
We need some way to check memory allocation or something, or at least find out how null boolexprs actually do leak (if they do). Hmm sortof stating the obvious here aren't I...
Al least they do leak for Groups but not for TriggerRegisterPlayerUnitEvent, that's a fact.
 

Romek

Super Moderator
Reaction score
963
> No lol, it's a lame thing for group,
Well, we can come to a conclusion that null boolexpr with groups leaks.

> Needing more tests :p
Here:

JASS:
scope test initializer Init

    globals
        group G = CreateGroup()
        trigger T = CreateTrigger()
    endglobals
    
    function Tr takes nothing returns boolean
        return true
    endfunction

    private function Exp takes nothing returns nothing
        //call TriggerRegisterPlayerUnitEvent(T, Player(0), EVENT_PLAYER_UNIT_DEATH, null)
        call TriggerRegisterPlayerUnitEvent(T, Player(0), EVENT_PLAYER_UNIT_DEATH, Filter(function Tr))
        //call GroupEnumUnitsInRange(G, 0., 0., 0., null)
       // call GroupEnumUnitsInRange(G, 0., 0., 0., Filter(function Tr))
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.01, true, function Exp)
    endfunction

endscope

I tried that. It's much more difficult to see because of the handle being created every 0.01 seconds. Although, yet again. The null one seems to increase memory usage much more rapidly.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
But you leak events, your test is bad.
That's why i destroy and create a new trigger all the time in the test code.
 
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