memory leaks - weeding them out completely

D

dArKzEr0

Guest
What type of information leaks? I'm under the impression that only handles leak (integers, reals, and booleans do not). So if I have:

Set casterUnit = (Casting unit)
Set casterPoint = (Position of casterUnit)
Set casterOwner = (Owner of casterUnit)
Set casterRange = 600.00
Set targetGroup = (Units within casterRange of casterPoint matching (((Picked unit) belongs to an enemy of casterOwner) Equal to True))

How do you effectively eliminate leaks?

set udg_casterUnit = null

call RemoveLocation( udg_casterPoint ) //does this also set the variable null or does the variable leak? What exactly happens when you remove the location? basically, do i need to use "set udg_casterPoint = null", and if not, why not? Alternatively, if I do use "set = null" do I still need to destroy the location?

set udg_casterOwner = null

//casterRange does not need to be nullified because reals do not leak

call DestroyGroup( udg_targetGroup ) // same question as RemoveLocation(); does the variable leak and do you need to "set udg_targetGroup = null" - why not?

Not sure if I made sense. I'll try to clarify if I didn't.

-darkz
 

Monovertex

Formerly Smith_S9
Reaction score
1,461
I have no answer, but I'd like to know this too. I always destroy the groups or locations then set them to null...
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Isn't this covered in one of the memory leaks tutorials?


Set point = positon ...
call RemoveLocation(point)
Set point = null

Set group = units in ...
call DestroyGroup(group)
Set group = null

Set unit = unit
Set unit = null

Note that the "set ... = null" isn't really needed on global variables.
They are reassigned eventually.
On locals, it's a must.


As an example, let's say you create a local group:

local group g = CreateGroup() // You have a variable, called g, of type unit-group, which points to an empty group
g -> group

call GroupAddUnit(g, GetTriggeringUnit()) // A unit is added to the group
g -> group -> unit

call DestroyGroup(g) // The contents of the group are destroyed
g -> group

Set g = null // It's all gone
g

Your function can savely return.


> matching (((Picked unit)

Hm... :p


> I always destroy the groups or locations then set them to null

Good plan.
 
D

dArKzEr0

Guest
AceHart said:
> matching (((Picked unit)

Hm... :p

:eek: I made the post pretty quickly.

Thanks for the explanation. I don't think any of the tuts cover the concept you explained, they only tell you how to remove the leak (not what removing does).

-darkz
 

SFilip

Gone but not forgotten
Reaction score
634
every handle is actually an integer (thus making H2I possible) that contains an "address" to the actual data. by simply doing CreateGroup (all gui functions do this) for example you fill the variable itself with something like 12103494 and create a group somewhere in your memory (which you later fill, but even while empty it takes some memory). now when you reassign the variable you will change 12103494 to something else and create another group somewhere in your memory - but the one you had before will also stay there. one group doesn't take too much space - 1kb at most. but imagine what happens if you create a group every 0.01 seconds. that's where destroygroup comes in...once you destroy a group you remove it from the memory, but the address stays. however once you reassign the variable this variable you simply do creategroup again which simply makes it take place of the old one in your memory.
now i'm not really sure why do you have to set local handles to null, but i guess they simply stay in your memory once the function is over although you can't use them anymore.
and once again to clear things up - there is absolutely no need to set globals to null. its just a waste of space since the effect is same even if you don't do that...

edit: 2500th post :D
 
C

CryptWizard

Guest
Ooohh... I get it now, so a handle is the JASS equivalent of a pointer from other programming languages.
 

SFilip

Gone but not forgotten
Reaction score
634
CryptWizard said:
Ooohh... I get it now, so a handle is the JASS equivalent of a pointer from other programming languages.
exactly.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Well,
- this is off-topic for this thread
- "It doesn't work" is not a very good problem description
- groups are handles regardless

But, given you had some thread about it, why not revive it with the "it doesn't work" trigger? :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top