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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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