• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

JASS - Several questions

Status
Not open for further replies.
Level 6
Joined
Jan 12, 2011
Messages
110
Hello,
I just wanted to ask several questions regarding JASS scripting.
1. What about "call DestroyEffectBJ(AddSpecialEffectLocBJ(Params...))" with param being the actual Special Effect creation ? Will this do any bad, leaks etc?
2. What about using "call TriggerSleepAction(X.Y)"? Is it safe to use in general? What about in loops? Any preference for this or for the "call PolledWait(X.Y)"?
3. Just to ensure - local variables MUST be always removed and then nulled, except for real/int/string? Or String should be also nulled?

Thanks for clarifying these queries!
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
1. AddSpecialEffectLocBJ creates and returns a special effect, which uses memory. DestroyEffectBJ destroys the special effect (which is returned by AddSpecialEffectLocBJ) freeing the memory, so no memory leak occurs.

its the same as
JASS:
local effect e = AddSpecialEffectLocBJ(...)
call DestroyEffectBJ(e)
just a bit shorter and without the need to use a variable

if you want to code in JASS you should not be using BJ functions. Also avoid using locations, as (x,y)-coordinates are a lot better.

2.TriggerSleepAction is the same as the GUI wait. It's inaccurate. I don't know much about TriggerSleepAction or PolledWait, because I prefer to use timers. They are better in most cases.

3.you need to remove objects, before you null the variable. Once the variable is nulled or overwritten you can no longer access the object it previously pointed to and this object leaks.
additionally local variables must also be nulled, except for the primitive types: int, real, boolean, string
 
Level 6
Joined
Jan 12, 2011
Messages
110
1. AddSpecialEffectLocBJ creates and returns a special effect, which uses memory. DestroyEffectBJ destroys the special effect (which is returned by AddSpecialEffectLocBJ) freeing the memory, so no memory leak occurs.

its the same as
JASS:
local effect e = AddSpecialEffectLocBJ(...)
call DestroyEffectBJ(e)
just a bit shorter and without the need to use a variable

if you want to code in JASS you should not be using BJ functions. Also avoid using locations, as (x,y)-coordinates are a lot better.

2.TriggerSleepAction is the same as the GUI wait. It's inaccurate. I don't know much about TriggerSleepAction or PolledWait, because I prefer to use timers. They are better in most cases.

3.you need to remove objects, before you null the variable. Once the variable is nulled or overwritten you can no longer access the object it previously pointed to and this object leaks.
additionally local variables must also be nulled, except for the primitive types: int, real, boolean, string

Thank you very much for the tips!
Appreciated!



Or function parameter declared local variables. The bug is only with local declared local handle variables.

Not quite sure I am following on this one. Function declares parameter in its "head" lets say, however there is no "local" thing there. But I guess I see the note about not needing to nullify these params.
What bug is with the local handle?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Not quite sure I am following on this one. Function declares parameter in its "head" lets say, however there is no "local" thing there. But I guess I see the note about not needing to nullify these params.
JASS:
function LocalExample takes unit u1 returns nothing
    local unit u2
    set u1 = null // This is a function parameter declared local variable
    set u2 = null // This is a local declared local variable
endfunction
What bug is with the local handle?
The local declared local handle variable reference counter leak on return bug.

In order for a handle index to be recycled it must have no existing references to it. Every time a variable is assigned to a handle it increments the reference counter by 1. Every time a variable is assigned a different handle it decrements the counter by 1. Since local variables are also destroyed on function return it is meant to automatically decrement the counter by 1 before then as well. The bug is that this only happens for function parameter declared local variables. Local declared local variables do not decrement the handle counter when destroyed on function return, resulting in the handle index never being recycled, even long after the object it represented was destroyed.
 
Status
Not open for further replies.
Top