1. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  2. Melee Mapping Contest #3 - Results are out! Congratulate the winners and check plenty of new 4v4 melee maps designed for this competition!
    Dismiss Notice
  3. The winners of our cinematic soundtrack competition have been decided! Step by the Music Contest #11 - Results to check the entries and congratulate the winners!
    Dismiss Notice

[JASS] Memory Leak Questions

Discussion in 'Triggers & Scripts' started by Blue_Jeans, Jun 21, 2007.

  1. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    If I understand the memory leaks correctly, the following code would not leak:
    Code (vJASS):
    function Trig_SG takes nothing returns nothing
        call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
    endfunction

    function Trig_SG_Actions takes nothing returns nothing
        call ForForce( GetPlayersAll(), function Trig_SG )
    endfunction

    //===========================================================================
    function InitTrig_Starting_Gold takes nothing returns nothing
        set gg_trg_Starting_Gold = CreateTrigger(  )
        call TriggerAddAction( gg_trg_Starting_Gold, function Trig_SG_Actions )
    endfunction

    But this would, because of the timer, not because of the Group:
    Code (vJASS):
    function Trig_Gold_Over_Time takes nothing returns nothing
        call AdjustPlayerStateBJ( 25, GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD )
    endfunction

    function Trig_Gold_Over_Time_Actions takes nothing returns nothing
        call ForForce( GetPlayersAll(), function Trig_Gold_Over_Time )
    endfunction

    //===========================================================================
    function InitTrig_Gold_Over_Time takes nothing returns nothing
        set gg_trg_Gold_Over_Time = CreateTrigger(  )
        call TriggerRegisterTimerEventPeriodic( gg_trg_Gold_Over_Time, 30.00 )
        call TriggerAddAction( gg_trg_Gold_Over_Time, function Trig_Gold_Over_Time_Actions )
    endfunction

    Am I correct?
     
  2. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Nope, it's the group that leaks.

    The event doesn't leak.

    In other news, BJs are nasty --

    GetPlayersAll() can be replaced with bj_FORCE_ALL_PLAYERS

    TriggerRegisterTimerEventPeriodic( trigger, time ) can be replaced with TriggerRegisterTimerEvent( trigger, time, true )

    AdjustPlayerStateBJ( amount, player, resource) can be replaced with SetPlayerState( player, resource, GetPlayerState( player, resource ) + amount )
     
  3. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    Even though this is "converted GUI", this should go to the Jass section.
    ~Thread moved (I hope, lol)
     
  4. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    @paskovich

    It's actually NOT converted GUI. It's just simple and I'm not an expert by any standards in JASS. I learned JASS (somewhat) by converting triggers I understood, which is why it looks like converted GUI. Even the equals signs are the same amount. I just felt like I should copy their style, dunno why.

    I wasn't entirely sure where to stick this thread because although the code is done in JASS, the question was not about JASS itself, so I didn't know where to stick it.

    So, if I understand this right, all players group does in fact leak? I've read several things saying it didn't, but what do I know?

    So this shouldn't leak (I think):
    Code (vJASS):
    function Gold_Over_Time takes nothing returns nothing
        call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD ) + 25 )
    endfunction
    function Gold_Over_Time_Actions takes nothing returns nothing
        call ForForce( bj_FORCE_ALL_PLAYERS, function Gold_Over_Time )
    endfunction
    //===========================================================================
    function InitGold_Over_Time takes nothing returns nothing
        set gg_trg_Gold_Over_Time = CreateTrigger( )
        call TriggerRegisterTimerEvent( gg_trg_Gold_Over_Time, 30, true )
        call TriggerAddAction( gg_trg_Gold_Over_Time, function Gold_Over_Time_Actions )
    endfunction

    Edit:Made it less "GUI"-like, for pask mostly.
     
    Last edited: Jun 22, 2007
  5. panther-anthro

    panther-anthro

    Joined:
    Oct 23, 2006
    Messages:
    361
    Resources:
    2
    Maps:
    2
    Resources:
    2
    Yes, you have to set the group to a variable and then use custom groups to destroy the variable. So you can continually use it for multiple groups, It's something I use to great effect in my hosted project.
     
  6. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    Groups in general leak, which I know. I'd heard that the all players group does not leak, but I don't know for sure. Does it, or does it not, leak?
     
  7. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    The only "Player group" (force) that doesn't leak is (All Players) (aka bj_FORCE_ALL_PLAYERS)

    So you're fine

    Also, I WAS wrong earlier about that - thought it was a unit group, and I don't know why o_O
     
  8. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    Also, this code validates, but doesn't work:
    Code (vJASS):
    function GoldOverTime takes nothing returns nothing
        call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD ) + 25 )
    endfunction

    function GoldOverTimeActions takes nothing returns nothing
        call ForForce( bj_FORCE_ALL_PLAYERS, function GoldOverTime )
    endfunction

    //===========================================================================
    function InitTrig_GoldOverTime takes nothing returns nothing
        set gg_trg_GoldOverTime = CreateTrigger()
        call TriggerRegisterTimerEvent( gg_trg_Gold_Over_Time, 30, true )
        call TriggerAddAction( gg_trg_GoldOverTime, function GoldOverTimeActions )
    endfunction

    Every 30 seconds you are supposed to get 25 more gold. Help?
    I worked before made the changes purplepoot said to make. I'm thinking I used something wrong?
     
    Last edited: Jun 22, 2007
  9. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    It's just what you had, but with the leaks/BJs removed ><

    If you want to test if it's even going off, add, right above the ForGroup, the line

    Code (vJASS):
    call BJDebugMsg("asdf")
     
  10. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    Hmmm... recoded from scratch and it works, reposted it above. Must have had a typo somewhere, but strangely the parser gave no errors. Thanks.

    So, to sum it up:
    1. Don't use BJ's if possible
    2. bj_FORCE_ALL_PLAYERS doesn't leak, but all other groups do.

    Question! Why exactly are the BJ's bad? You merely said nasty and didn't explain, but I'd like to know why. Inefficient? Leak? What?

    For example, SetUnitVertexColor and SetUnitVertexColorBJ:
    Code (vJASS):
    native          SetUnitVertexColor  takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing

    Code (vJASS):
    function SetUnitVertexColorBJ takes unit whichUnit, real red, real green, real blue, real transparency returns nothing
        call SetUnitVertexColor(whichUnit, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
    endfunction


    Obviously I see the difference between the two as far as what they do, but are BJ's merely inefficient? I see no leaks or anything, but perhaps this is a bad example?
     
  11. paskovich

    paskovich

    Joined:
    Jul 12, 2005
    Messages:
    794
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    No, Blue_Jeans, that's a perfect example of a BJ. It is inefficient, as you said. The BJ calls the native, someimes with a little maths inside, but sometimes simply changing the order of parameters (like "*Swapped()" functions). But why use BJ, when you can call the native instantly? Also, there are functions like PolarProjectionBJ, that use mathematical calculation to get the target point of the previous point. But it uses locations as a parameter, and as a return value, but the whole thing can be done with coordinates. BJs are a waste of CPU speed.

    PS: Don't overreact, but this thread has nothing to do with spells or systems, but it included Jass, so I moved it to the right section. That's all, no problem.
     
  12. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Also, you know how slow "Sin" is, right?

    Well, vex did some tests, and Sin (being a native) ran slightly faster than DoNothing(), which is a custom function with no contents.

    So BJs are slow, very slow.
     
  13. Blue_Jeans

    Blue_Jeans

    Joined:
    Jun 30, 2006
    Messages:
    233
    Resources:
    0
    Resources:
    0
    I had stuck it in Spells and Systems? ROFL, my bad entirely. So BJ's are simply inefficient.
    Note to self: No BJ's...
     
  14. PurplePoot

    PurplePoot

    Joined:
    Dec 14, 2005
    Messages:
    11,162
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    Some BJs are good in a good amount of cases, generally the long ones, like PolledWait or TriggerRegisterAnyUnitEventBJ