Checking leaks in JASS?

woot

New Member
Reaction score
8
function CheckHeartyAura

group g isn't nulled. That leaks a handle.

nope

i've since nulled the group.. doesn't change anything


do I have to null groups like that? I'm using DestroyGroup.. shouldn't that work?
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
>do I have to null groups like that? I'm using DestroyGroup.. shouldn't that work?
You need to do both. Destroy it, then null it. In that order.
 

woot

New Member
Reaction score
8
I've gone through my code and done everything suggested.. still i'm getting leaks for this


Code:
Test
    Events
        Player - Player 1 (Red) types a chat message containing -test as An exact match
    Conditions
    Actions
        Set tempGroup = (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))
        Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
            Loop - Actions
                Hero - Set (Picked unit) Hero-level to 10, Hide level-up graphics
                Unit - Set mana of (Picked unit) to 100.00
                Set tempUnit = (Picked unit)
        Custom script:   call DestroyGroup(udg_tempGroup)


i type -test a few times and the handle counter actually goes down each time.. then it starts to go up.. by increments of 1 or 2 each time i type -test (actually sometimes it goes up by 3 or 4)


I don't get why this is leaking handles in the first place.. let alone the odd way it is leaking handles..

can anyone help?

:(
 

trb92

Throwing science at the wall to see what sticks
Reaction score
142
Code:
Test
    Events
        Player - Player 1 (Red) types a chat message containing -test as An exact match
    Conditions
    Actions
        [B]Set tempGroup = (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))[/B]
        Unit Group - Pick every unit in [U](Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))[/U] and do (Actions)
            Loop - Actions
                Hero - Set (Picked unit) Hero-level to 10, Hide level-up graphics
                Unit - Set mana of (Picked unit) to 100.00
                Set tempUnit = (Picked unit)
        Custom script:   call DestroyGroup(udg_tempGroup)
You set the variable, where it's bolded, but don't use the variable in the underlined part... Of course it's leaking. Your creating two groups, but only destroying one.
 

woot

New Member
Reaction score
8
LOL oops .. wow .. 1 sec let me check it out..


...



... that didnt fix it.. the counter is now going up slower but it is still going up after going down in the same fashion


new trigger:

EDIT:

ive simplified the trigger.. this is exactly what causes the leak:

Code:
Test
    Events
        Player - Player 1 (Red) types a chat message containing -test as An exact match
    Conditions
    Actions
        Set tempGroup = (Units in (Playable map area) matching (((Matching unit) is A Hero) Equal to True))
        Custom script:   call DestroyGroup(udg_tempGroup)

what's going on? why is it leaking handles? =\
 

Romek

Super Moderator
Reaction score
963
If it goes up, and then goes down. Then you're not leaking. If it constantly goes up, then you are.
 

woot

New Member
Reaction score
8
If it goes up, and then goes down. Then you're not leaking. If it constantly goes up, then you are.

i start the game and as I type it the count goes down at first but as I continue typing it in it keeps going up and up and up
 

Romek

Super Moderator
Reaction score
963
It might be something else that's leaking. That thing is very sensitive.
Are units being created?
Effects?

etc..
 

quraji

zap
Reaction score
144
I haven't looked at how the system works, but if it does the way I would think, then increasing handle counts aren't bad necessarily. It should count handles, not leaks. If you were to create a hero for a player, the handle count would go up, but it's obviously not a leak since you want the hero to stay in existence.

So make sure that you're not mistaking valid increased handle counts as leaks.

Note that I have looked neither at your code nor the code of the handle counter, just mentioning what I think may be happening :thup:
 

woot

New Member
Reaction score
8
It might be something else that's leaking. That thing is very sensitive.
Are units being created?
Effects?

etc..

i really can't think of anything else that would be created from such a simple function as setting a global variable to a group of units and then destroying the group.. called after the event of player 1 typing "-test"

i'm thoroughly confused
 

Terrabull

Veteran Member (Done that)
Reaction score
38
Wait wait, you have to null units? I thought that local unit variables didn't leak a handle. Well crap, that might explain some of my problems.
 

Flare

Stops copies me!
Reaction score
662
Hmmm, was just reading through the Grimoire manual, and saw
War3err traces allocation of locations and groups. It keeps tracks of attempted double frees,
free(null) and leaks. Leak statistic reports can be extracted by call RemoveLocation(ItoLoc(-1))
and call DestroyGroup(ItoGrp(-1)).
May be of help, but
1) I don't know how it works (I assume it does work though, otherwise it wouldn't be there :p)
2) I don't know if it requires you to start WC3 with Grimoire (if so, you're screwed if you have latest version of WC3)
3) If it doesn't, I haven't a clue where it extracts those statistic to
4) Not sure how exactly to use it (I'm guessing it's something similar to importing the stopwatch natives, but I don't really know)

Has anyone actually tried this to see how you get it working, and how well it works?
 

Romek

Super Moderator
Reaction score
963
Hmmm, was just reading through the Grimoire manual, and saw

May be of help, but
1) I don't know how it works (I assume it does work though, otherwise it wouldn't be there :p)
2) I don't know if it requires you to start WC3 with Grimoire (if so, you're screwed if you have latest version of WC3)
3) If it doesn't, I haven't a clue where it extracts those statistic to
4) Not sure how exactly to use it (I'm guessing it's something similar to importing the stopwatch natives, but I don't really know)

Has anyone actually tried this to see how you get it working, and how well it works?
It requires you to start WC3 with Grimoire.
 

SFilip

Gone but not forgotten
Reaction score
633
> I assume it does work though
It did with 1.21, but not anymore.
 

Terrabull

Veteran Member (Done that)
Reaction score
38
If I have code like this:
local unit CB = GetSellingUnit()
do I have to set CB to null at the end? Even if nothing else happens to that variable?
 

Terrabull

Veteran Member (Done that)
Reaction score
38
JASS:
function Cond_Dual_Damage_Towers takes nothing returns boolean
    local integer UID= GetUnitTypeId(GetTriggerUnit())
    return UID == 'n00E' or UID == 'n00I' or UID == 'n004' or UID == 'n00F' or UID == 'n00G'
endfunction


Okay, one last question then. The above obviously leaks. So is it better to not use the local at all?
I would have to make a local boolean, store that, null the unit, and then return the boolean, is that going to be more work than it's worth? (for the engine, not for me)
 

Flare

Stops copies me!
Reaction score
662
No leak there :p AFAIK, handle-type globals and function parameters don't need nulling.

As regards returned values e.g. GetTriggerUnit (), I don't think you have to replace the function call with a local to avoid a leak (but, if you do use set localUnit = GetTriggerUnit (), you will have to null localUnit)

I'm not so sure about something like
JASS:
function GiveMeAUnit takes nothing returns nothing
  local unit u = ...
  call ManipulateUnitInSomeWay (u, ...)
  return u
endfunction

I've seen some people say that it leaks a handle (I think it was cohadar), and other people say that it doesn't (I forget who exactly). Either way, you could just use a global variable instead of the local, just to be safe
 
B

bountygiver

Guest
For local variables, you need to nullify all of the locals used in the function at the end of the function.

For instance,

JASS:
function XXXX takes nothing returns nothing
     local unit u = (Specify Unit)

     -Insert functions here
     
     set u = null
endfunction


For locals such as locations and groups, they cause a double leak, so watch out. You need to add a RemoveLocation, DestroyGroup etc. order before nullifying the values.
 
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