WC3Jass.com Forum Index WC3Jass.com
"The Jass Vault"
 
 FAQ   Search   Memberlist   Usergroups   Register 
 Profile   Log in to check your private messages   Log in  
 Forum   Scripts   Files   Chat   Pastebin   Function finder  
Affiliates
The HIVE Workshop Games Modding
The Hubb Wc3Campaigns
WC3-Mapping.net

Cleaning up leaks
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    WC3Jass.com Forum Index -> Tutorials
View previous script :: View next script  

Author
Blade.dk


Joined: 20 Apr 2005
Posts: 608
Back to top
Message
PostPosted: Fri Jun 03, 2005 6:19 pm    Post subject: Cleaning up leaks Reply with quote

This tutorial will give you a base information on how to remove leaks in Jass, and has a list of the functions that we use for destroying/removing objects.
If you don't now Jass, yet, this ain't the rigth tutorial for you.

Nullifying

When you have used a local variable which type is handle (or child of handle, or child of a child of handle), you have to nullify it to prevent the variable from leaking
You do that by simply setting it to null. Most people do this just before the 'endfunction' in their functions. Example:

Code:
function MyFunc takes nothing returns nothing
    local unit c = GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local real r = GetRandomReal(0.00,1.11)
    local string s = "Don't be an ass; learn Jass!"
    ... // Put some action here.
    set c = null // item and unit are children of widget which is child of handle. Therefore we need to nullify them.
    set i = null
endfunction


Notice that we don't nullify the real local and the string local they aren't extended handles therefore there is no need to nullify them.

Here is a list of types which don't need to be nullified, to help people not familiar with Jass:

Code:
string, real, integer, code, boolean


Destroying Objects

This is a list of the actions we use to destroy/remove objects. Note that you if you have stored the objects you want to remove in a local variable you still have to nullify the local. Just remembe that that MUST be done AFTER the removing of the objects, else it will point to null, and nothing will be removed/destroyed.

Code:
boolexpr
    call DestroyBoolExpr(someBoolExpr)
conditionfunc
    call DestroyCondition(someConditionFunc)
defeatcondition
    call DestroyDefeatCondition(someDefeatCondition)
effect
    call DestroyEffect(someEffect)
filterfunc
    call DestroyFilter(someFilterFunc)
fogmodifier
    call DestroyFogModifier(someFogModifier)
force
    call DestroyForce(someForce)
group
    call DestroyGroup(someGroup)
image
    call DestroyImage(someImage)
itempool
    call DestroyItemPool(someItemPool)
leaderboard
    call DestroyLeaderboard(someLeaderboard)
lightning
    call DestroyLightning(someLightning)
multiboard
    call DestroyMultiboard(someMultiboard)
quest
    call DestroyQuest(someQuest)
texttag
    call DestroyTextTag(someTextTag)
timer
    call DestroyTimer(someTimer)
timerdialog
    call DestroyTimerDialog(someTimerDialog)
trigger
    call DestroyTrigger(someTrigger)
ubersplat
    call DestroyUbersplat(someUbersplat)
unitpool
    call DestroyUnitPool(someUnitPool)
gamecache
    call FlushGameCache(someGameCache)
unit
    call RemoveUnit(someUnit)
item
    call RemoveItem(someItem)
location
    call RemoveLocation(someLocation)
rect
    call RemoveRect(someRect)
region
    call RemoveRegion(someRegion)
weathereffect
    call RemoveWeatherEffect(someWeatherEffect)

_________________
#wc3dev
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Author
Edwardswolentoe


Joined: 29 Jul 2005
Posts: 144
Back to top
Message
PostPosted: Mon Sep 26, 2005 10:55 am    Post subject: Reply with quote

How do you null a local if it is the value you return at the end of the function?
View user's profile Send private message Send e-mail MSN Messenger

Author
Blade.dk


Joined: 20 Apr 2005
Posts: 608
Back to top
Message
PostPosted: Mon Sep 26, 2005 11:33 am    Post subject: Reply with quote

Edwardswolentoe wrote:
How do you null a local if it is the value you return at the end of the function?


There is really no way, but you can use H2I and a unleaking integer local like this:

Code:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function blah takes nothing returns location // I know this function sucks, but it's just to have an example
    local location l = Location(12345, 678910)
    local integer i = H2I(l)
    set l = null
    return i
    return null
endfunction

_________________
#wc3dev
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Author
Themerion


Joined: 25 Jan 2006
Posts: 14
Back to top
Message
PostPosted: Wed Jan 25, 2006 10:29 pm    Post subject: Reply with quote

I suppose that the "takes values" have to be nullified as well, if they are children to widget?
View user's profile Send private message

Author
phyrex1an


Joined: 28 Jun 2005
Posts: 68
Back to top
Message
PostPosted: Thu Jan 26, 2006 4:16 pm    Post subject: Reply with quote

You don't need to null the 'take vaules'. That is atleast the latest Ive heard.
View user's profile Send private message

Author
Blade.dk


Joined: 20 Apr 2005
Posts: 608
Back to top
Message
PostPosted: Thu Jan 26, 2006 8:13 pm    Post subject: Reply with quote

phyrex1an is right.
_________________
#wc3dev
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Author
PipeDream


Joined: 20 Nov 2005
Posts: 294
Back to top
Message
PostPosted: Fri Jan 27, 2006 8:07 am    Post subject: Reply with quote

Yeah.. you wonder how blizzard fucked that one up =)
You might add the use of a wrapper function for a local var when you need to return the handle.
View user's profile Send private message

Author
lookoverthere
Guest



Back to top
Message
PostPosted: Fri Feb 10, 2006 3:52 am    Post subject: Reply with quote

I have no programming background whatsoever so can somebody pls explain what exactly those handle funtions do?(I know how to use the handles already) Why does returning an integer value also return the location value unless the integer is referenced from what it is set to. I would assume once the value is determined for a variable, that value is no llonger dependent.

Author
Rising_Dusk


Joined: 07 Apr 2006
Posts: 55
Back to top
Message
PostPosted: Fri Apr 07, 2006 7:25 pm    Post subject: Reply with quote

I've got to ask.
In terms of boolexpr's, is it necessary to destroy them at the end of every code?

I wasn't aware leaving them around would leak at all, but I'm just making sure.
View user's profile Send private message Visit poster's website AIM Address

Author
PipeDream


Joined: 20 Nov 2005
Posts: 294
Back to top
Message
PostPosted: Fri Apr 07, 2006 11:20 pm    Post subject: Reply with quote

Functions that return type boolexpr will allocate a new boolexpr. If nothing is using that boolexpr, it needs to be deallocated. I have stayed away from boolexpr's like the plague, so I have no examples.
_________________
jass.vim
View user's profile Send private message

Author
PurplePoot


Joined: 20 Dec 2005
Posts: 272
Back to top
Message
PostPosted: Wed Apr 12, 2006 10:57 pm    Post subject: Reply with quote

to get rid of a triggeraction, do u just use TriggerRemoveAction, or is there something else you also have to do?
View user's profile Send private message

Author
Blade.dk


Joined: 20 Apr 2005
Posts: 608
Back to top
Message
PostPosted: Wed Apr 12, 2006 11:08 pm    Post subject: Reply with quote

TriggerRemoveAction is enough.
_________________
#wc3dev
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Author
PurplePoot


Joined: 20 Dec 2005
Posts: 272
Back to top
Message
PostPosted: Wed Apr 12, 2006 11:53 pm    Post subject: Reply with quote

lookoverthere wrote:
I have no programming background whatsoever so can somebody pls explain what exactly those handle funtions do?(I know how to use the handles already) Why does returning an integer value also return the location value unless the integer is referenced from what it is set to. I would assume once the value is determined for a variable, that value is no llonger dependent.


dont forget, this is what i think

every type ( for example footman ) has an integer associated with it ( 'hf00' is an example ). Therefore, every object also has an integer specifically for it. By returning the int then returning null(handle reference) it assumees you are returning the handle associated with 10562534 or something like that. Since every timer/unit/whatever has a different one of these, that is what makes them multiinstanceable.
View user's profile Send private message

Author
PipeDream


Joined: 20 Nov 2005
Posts: 294
Back to top
Message
PostPosted: Thu Apr 13, 2006 12:06 am    Post subject: Reply with quote

I think you are confused on a couple issues. First of all, the way data is structured. take:
Code:
local unit u = CreateUnit(Player(0),'hfoo',0,0,0)

u itself is an integer. This integer points to a "handle" structure. which does nothing important for this discussion. That internal handle structure points to a unit structure, which contains the player, position, facing angle information, along with a pointer to the unit type structure- the 'hfoo'. The 'hfoo''s connection to the integer u is rather tenuous and indirect.

Secondly, what makes code not-multiinstanceable is that every timer, unit etc has a different address. Of course, for them to be different unit/timers we need them to have different addresses. So if we have a unit in a global, and we try to reuse that global for a different unit, we're going to step on our own toes. We need a separate work space or "scope" for each trigger instance for multiinstanceability.
_________________
jass.vim
View user's profile Send private message

Author
grupoapunte
Guest



Back to top
Message
PostPosted: Sat Apr 29, 2006 10:22 pm    Post subject: Reply with quote

Ok let me see if i get it, if i have this simple function:

endfunction
" target="_blank" class="postlink">
function func takes nothing returns nothing
call DisplayTextToForce( GetForceOfPlayer(GetOwningPlaye (GetManipulatingUnit())), "This function leaks a lot")
endfunction


that will leak right so to fix it i would have to do this:

call DestroyForce(f)
set f = null
set u = null
endfunction
" target="_blank" class="postlink">
function func takes nothing returns nothing
local unit u = GetManipulatingUnit()
local force f = GetForceOfPlayer(GetOwningPlayer(u))
call DisplayTextToForce( f, "This function isnt leaking")
call DestroyForce(f)
set f = null
set u = null
endfunction


i suppose thats fine, but im wondering if GetOwningPlayer(u) leaks, and in case it does how do i clear it?

Am i missing something in the fixed function?

Thanks, grupoapunte.

PS: sry for not registrering, im registrated in many forums including wc3campaings and i folowed this post from there.

Display posts from previous:   
Post new topic   Reply to topic    WC3Jass.com Forum Index -> Tutorials All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


FSDark by SkaidonDesigns
Powered by phpBB © 2001, 2002 phpBB Group