• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

[Solved] Destroying Groups in JASS?

Status
Not open for further replies.
Level 20
Joined
May 16, 2012
Messages
635
So, i've moved to Jass to make my MUI triggers easier, and im not sure if this code destroy the created group or not.

JASS:
function ReleaseDmg_Actions takes nothing returns nothing
local unit u
local location l
local group g
set u = GetTriggerUnit()
set l = GetUnitLoc(u)
set g = GetUnitsInRangeOfLocMatching(1000.00, l, Condition(function ReleaseDmg_Filter))
    call CreateNUnitsAtLoc( 1, 'n02S', GetOwningPlayer(u), l, bj_UNIT_FACING )
    call UnitApplyTimedLifeBJ( 2.00, 'BTLF', GetLastCreatedUnit() )
    call ForGroupBJ( g, function ReleaseDmg )
    set udg_Molten_Store[GetUnitPointValue(u)] = 0
    set u = null
    set l = null
    set g = null
endfunction

So by doing,
JASS:
set g = null
, am i destroying the group and cleaning the leak or i should do,
JASS:
call DestroyGroup(g)
and then
JASS:
set g = null
to properly do it?

And how about local triggers? I need to set then to null after registering or they are like integers and real?
 
Destroy and then only null the group. Following this rule you leak atm.
Triggers, which are never destroyed do not need to be nulled.

If you are interested in explainations you can read this: http://www.hiveworkshop.com/threads/memory-leaks.263410/#post2661133

If you are using JNGP editor you can have a look into the function list to see what is behind the red highlighted functions.
They are wrappers functions for other code, which can often be used directly by you instead calling the wrapper function.
 
Level 20
Joined
May 16, 2012
Messages
635
Destroy and then only null the group. Following this rule you leak atm.
Triggers, which are never destroyed do not need to be nulled.

If you are interested in explainations you can read this: http://www.hiveworkshop.com/threads/memory-leaks.263410/#post2661133

If you are using JNGP editor you can have a look into the function list to see what is behind the red highlighted functions.
They are wrappers functions for other code, which can often be used directly by you instead calling the wrapper function.
Thx!
 
afaik this is incorrect. They don't have to be nulled, but it is still a leak.

It shouldn't leak. Each agent has an integer "reference count" associated with it. When you assign a variable to that agent, its reference count goes up by 1. When you reassign the variable or null it, that reference count goes down by 1. When you remove an agent, wc3 checks if the reference count is 0 before it frees the handle ID and the associated memory (a pointer + the reference count).

So if you null the triggers, those reference counts will end up being 0, but it won't really matter in the end since we're not going to remove it. So no memory is saved.

But it is probably easier to just null everything. It just takes extra mental power to determine whether something is permanent or not. Kinda like with parking brakes in cars. Some people will only put it up when you are on an incline. But tbh, it is easier to just put it up every time your park and not even think about it. Same idea here, heheh.
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,547
First off, good call Purge, you are correct and I am mistaken.

> But it is probably easier to just null everything. It just takes extra mental power to determine whether something is permanent or not.

It is also valuable to remove references to things even if they aren't leaked for static and dynamic analysis tools - not that vjass supports such a thing.
 
Status
Not open for further replies.
Top