• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] GetFilterUnit()

Status
Not open for further replies.
Level 11
Joined
Feb 22, 2006
Messages
752
uhhhh...locations ARE handles:

JASS:
type location extends handle


And handles DO leak. The entire point of nullifying handles is to prevent memory leaks.

In JASS, any variable type tht is not a(n): integer, real, boolean, string,
is a handle. (the four types listed above are hardcoded natives)

Since all handles can leak, make sure to nullify all local variables that don't belong to one of the above four types once you're done using them.

By the way, I'm not sure if GetFilterUnit() leaks. I just avoid FOR loops altogether so I never have deal with it.
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Leak != Lag
!!!! Learn Jass !!!!

there is a no way to make unit variable leak anyway
(may be if you make decay time unlimited and kill unit without remove and make it does decay :D)

Leak: Causing an unused value to fill your memory. It can be locations-unitgroups-special effects that you cant see but not destroyed (they are still used when they are visible)
For example you create a group
it lasts forever unless you dont destroy it
Groups - Locations - Ligthning Effects - Timers - Special Effects - Forces etc etc etc etc are objects just like units and they will exist until they get destroyed
and they will hold some memory while they are existing for sure
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
And handles DO leak. The entire point of nullifying handles is to prevent memory leaks.
Not all handles ;)

In JASS, any variable type tht is not a(n): integer, real, boolean, string, is a handle. (the four types listed above are hardcoded natives)
You forgot the 'code' type.

By the way, I'm not sure if GetFilterUnit() leaks.
It doesn't leak. What leaks is if you do something like this:
JASS:
local unit u=GetFilterUnit()
return GetUnitTypeId(u)=='LOLZ'
Which isn't nulling the local unit.
And anyway, I'm not even sure of the cause of the non-nulling leaks. I'm pretty sure it's just the handle ID that doesn't get recycled, so when you use something like I2S(H2I(somehandle)), a new string will be created, and thus leaking in strings. So I think that if you don't use gamecache, you don't even have to null locals (but I'm not sure... makes sense though).

I just avoid FOR loops altogether so I never have deal with it.
For loops are awesome. ForGroup is one of the best natives ever.
 
Level 3
Joined
Sep 4, 2007
Messages
49
There are 2 types of leaks, pointer leaks and handle leaks.

The pointer leaks make the biggest difference and that usually consists of not removing dummy units when your finished, not destroying effects when your finished, not destroying text tags when your finished, not destroying locations when your finished etc.

The other type of leak is pointer leak. Although the seriousness of this type of leak is debatle, often it goes un-noticed unless you use certain systems that implement the H2I - 0x100000 method for storing data or you somehow manage to leak over one million pointers :eek:
 
Level 5
Joined
Oct 27, 2007
Messages
158
It doesn't leak. What leaks is if you do something like this:
JASS:
local unit u=GetFilterUnit()
return GetUnitTypeId(u)=='LOLZ'
Which isn't nulling the local unit.


I agree that initializing variables, nulling pointers/handles etc, when not used further, is good programming practice. However the usefullness of nulling local handles at the end of a function I do question. Jass locals are not static locals. I have not seen one case in Jass where a local would retain its value in between function calls. They're on the stack and the stack space used is released after a function call. Therefore that one reference to the object is gone.

If you don't null that local handle, but do destroy the object, do you really think the local handle will still use memory? I don't, since its local and the stack memory its on will be released after the function call.
 
Level 5
Joined
Oct 27, 2007
Messages
158
Fixed:
They also destroy nothing.


What do you mean by that? Are you suggesting they don't clean up?
If that's the case then open some campaign maps of Blizzard. They do remove/destroy objects if they can leak. So its not like they do absolutely nothing against it.
 
Status
Not open for further replies.
Top