Removing Leaks in Jass

prismpirate

New Member
Reaction score
2
Are there any tutorials for removing leaks in Jass? All the tutorials seem to be only for GUI.
 

prismpirate

New Member
Reaction score
2
What data types leak then? Whenever I simplify bjs, there's always a function that nulls the boolean expressions. Do booleans leak too?
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
Not sure if they leak.
But, I can tell you that all locals that aren't of type integer or real need to be nulled. AttackType, DamageType, WeaponType are counted like integers.
JASS:

local unit u
set u = null
 

Tom Jones

N/A
Reaction score
437
Atomic types; integers, reals and booleans, doesn't need to be freed from memory or nulled.
Handle derived types need to be freed from memory and nulled. There is of course exceptions, you mentioned one of them.

Booleanexpressions will leak when used as argument for some EnumUnits...(...) functions, I can't remember which, however just use a static/constant booleanexpression and pass that to those functions.

Also And(...), Or(...) or Not(...) will create a new boolexpr which needs to be freed from memory and nulled.

Under any other circumstances you don't have to worry about booleanexpressions leaking.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Booleanexpressions will leak when used as argument for some EnumUnits...(...) functions, I can't remember which, however just use a static/constant booleanexpression and pass that to those functions.
Aside from that being wrong, you're right.

Filter(function x) will always return the same boolexpr, so they don't need freeing or nulling. The same is NOT true for those created with And, Or or Not, as Tom said.
 

Viikuna

No Marlo no game.
Reaction score
265
Yea, similiar boolexprs are stacked ( or something ) a lil bit like strings.

Its null boolexprs that leaves something behind when used with GroupEnum
 

Jesus4Lyf

Good Idea™
Reaction score
397
I can tell you that all locals that aren't of type integer or real need to be nulled.
Oh yeah, and Blitz is wrong too. Only agents need nulling, and even then players are an exception.

Text tags, boolexprs, players, strings etc all don't need nulling/destroying.

^Except for boolexprs created in the manner I mentioned above.
 

Viikuna

No Marlo no game.
Reaction score
265
Generally all handles ( or agents now? ) that are going to get removed in some point of the game.
 

prismpirate

New Member
Reaction score
2
Same. Everyone is saying different things. Someone consolidate a list? So far, I take it that:

integers
reals
strings
some boolexprs
texttags

don't need to be nulled. I've been nulling all units so far. I don't use much other than units, groups and locations, although I try to keep it to x,y as much as possible.
 

Artificial

Without Intelligence
Reaction score
326
These ways of nulling go from easiest to hardest to remember, and from most inaccurate to most accurate (so first is easiest and most inaccurate, whereas the last one is hardest, but most accurate).

1st way: null all handles.
2nd way: null all agents.
3rd way: null every agent type you can create and destroy. For example units can be destroyed and created, whereas players or damagetypes can't be created nor destroyed.
4th way: null every agent that is going to (or might) be destroyed. For example triggers that are going to function throughout the game don't need to be nulled, as they are not going to be destroyed, but triggers that are going to be destroyed should also be nulled.

It doesn't harm to null stuff that doesn't have to be nulled, though, so you can just use some of the easier-to-remember ways if you want.
 

Rainther

I guess I should write something of value here...
Reaction score
61
Same. Everyone is saying different things. Someone consolidate a list? So far, I take it that:

integers
reals
strings
some boolexprs
texttags

don't need to be nulled. I've been nulling all units so far. I don't use much other than units, groups and locations, although I try to keep it to x,y as much as possible.

I suspect that you use locations with AngleBetweenPoints, DistanceBetweenPoints and PolarProjectionBJ, however you can do like I did:
JASS:
//Place these function into a library and use them instead of the functions mentioned above
function OrbitX takes real X, real dist, real angle returns real
    return ( X + dist * Cos(angle * bj_DEGTORAD) )
endfunction

function OrbitY takes real Y, real dist, real angle returns real
    return ( Y + dist * Sin(angle * bj_DEGTORAD) )
endfunction

function DisXY takes real X1, real Y1, real X2, real Y2 returns real
    local real dx = X2 - X1
    local real dy = Y2 - Y1
    return SquareRoot(dx * dx + dy * dy)
endfunction

function AngXY takes real X1, real Y1, real X2, real Y2 returns real
    return bj_RADTODEG * Atan2(Y2 - Y1, X2 - X1)
endfunction
It might feel harder to use, but I got used to it rather quickly.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, actually, you dont have to null unit variables pointing to some Hero, if that Hero will be revived after death ( for example some arena or AoS map ), but since you rarely know if it is a Hero or not, it is good to null all the units.

Then again, I dont null any units at all, because I recycle them all and they never really get removed.

If you have an effect that is never removed ( for example some attached effect in some Heros hands or somewhere ), you dont have to null it either.


Basicly it depends on situation. What I said in my previous post is the most generalized rule I can think of.

edit. Artificial explained it really nicely. Just pick one of those 4 options.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
You don't need to null variables of type code either, although I don't see them used often.
 

SanKakU

Member
Reaction score
21
i've been using and or and not a lot how do you null that stuff?

or maybe i should say, how do you use the variables for that and then null them?
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
I doubt you need to actually use And(), Or() and the rest of them. Instead, you can use this:

JASS:
function a takes nothing returns boolean
return And(b, c)
endfunction

function b takes nothing returns boolean
return b and c
endfunction


This is all freehanded, so it'll probably syntax error. But you get the idea.
 

SanKakU

Member
Reaction score
21
actually i don't. perhaps if you converted one of the following for me i'd understand what you mean.

JASS:
private function A takes nothing returns nothing
local integer i = GetSpellAbilityId()
if i == 'A01M' then
call DarkPossession()
else
if i == 'A05B' then
call WindRush()
else
if i == 'A05A' then
call ChainUp()
endif
endif
endif
endfunction

JASS:
private function A takes nothing returns nothing
set i = GetSpellAbilityId()
    if i == 'A00M' or i == 'A00K' or i == 'A03P' or i == 'A03O' or i == 'A03N' or i == 'A030' or i == 'A02P' or i == 'A02Z' or i == 'AMaE' then
    call epuseherospells()
    endif
endfunction


edit: hold on a moment...was he meaning the functions And() Or() ? i didn't realize those exist and i don't know how to use them...

anyway i've been thinking about it and what you coded i have no idea what it is.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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