 |
WC3Jass.com "The Jass Vault"
|
Affiliates
|
 |
|
 |
|
|
| Message |
Posted:
Fri Jun 03, 2005 6:19 pm Post subject:
Cleaning up leaks |
|
|
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 |
|
|
|
 |
|
 |
|
 |
 |
|
 |
|
|
| Message |
Posted:
Mon Sep 26, 2005 10:55 am Post subject:
|
|
|
| How do you null a local if it is the value you return at the end of the function? |
|
|
|
 |
|
|
|
| Message |
Posted:
Mon Sep 26, 2005 11:33 am Post subject:
|
|
|
| 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 |
|
|
|
 |
|
|
|
| Message |
Posted:
Wed Jan 25, 2006 10:29 pm Post subject:
|
|
|
| I suppose that the "takes values" have to be nullified as well, if they are children to widget? |
|
|
|
 |
|
|
|
| Message |
Posted:
Thu Jan 26, 2006 4:16 pm Post subject:
|
|
|
| You don't need to null the 'take vaules'. That is atleast the latest Ive heard. |
|
|
|
 |
|
|
|
| Message |
Posted:
Thu Jan 26, 2006 8:13 pm Post subject:
|
|
|
phyrex1an is right. _________________ #wc3dev |
|
|
|
 |
|
|
|
| Message |
Posted:
Fri Jan 27, 2006 8:07 am Post subject:
|
|
|
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. |
|
|
|
 |
|
|
|
| Message |
Posted:
Fri Feb 10, 2006 3:52 am Post subject:
|
|
|
| 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. |
|
|
|
 |
|
|
|
| Message |
Posted:
Fri Apr 07, 2006 7:25 pm Post subject:
|
|
|
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. |
|
|
|
 |
|
|
|
| Message |
Posted:
Fri Apr 07, 2006 11:20 pm Post subject:
|
|
|
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 |
|
|
|
 |
|
|
|
| Message |
Posted:
Wed Apr 12, 2006 10:57 pm Post subject:
|
|
|
| to get rid of a triggeraction, do u just use TriggerRemoveAction, or is there something else you also have to do? |
|
|
|
 |
|
|
|
| Message |
Posted:
Wed Apr 12, 2006 11:08 pm Post subject:
|
|
|
TriggerRemoveAction is enough. _________________ #wc3dev |
|
|
|
 |
|
 |
|
 |
 |
|
 |
|
|
| Message |
Posted:
Wed Apr 12, 2006 11:53 pm Post subject:
|
|
|
| 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. |
|
|
|
 |
|
 |
|
 |
 |
|
 |
|
|
| Message |
Posted:
Thu Apr 13, 2006 12:06 am Post subject:
|
|
|
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 |
|
|
|
 |
|
 |
|
 |
 |
|
 |
|
|
| Message |
Posted:
Sat Apr 29, 2006 10:22 pm Post subject:
|
|
|
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. |
|
|
|
 |
|
 |
|
 |
|
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
|
|