• 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] Remove Hash Location custom script?

Status
Not open for further replies.
Level 6
Joined
Sep 9, 2006
Messages
92
Could someone enlighten me on what custom script i would use to remove a location handle to stop it from leaking?

(is it similar to RemoveLocation(udg_TempPt)?)

(also on a side note, how do i make a toggle in posts to hide/show parts of the post? i.e. triggers, screenshots so they dont take up a huge area)
 
Level 6
Joined
Sep 9, 2006
Messages
92
Your post already contains the answer. Its "call RemoveLocation(udg_YourVar)".

also, you might want to have a look at hidden tags: [hidden=Title]Hidden text[/hidden] generates:
Hidden text

ahh kk ill use that when i post my spell once its completed :p

so how would that remove call work for a hash? i create the point with this:
  • Hashtable - Save Handle Of(Position of (Load (Key Target) of (Integer A) in DR_Hash)) as (Key TargetPt) of (Integer A) in DR_Hash
could you help me create a call to remove the TargetPt variable?
 
Level 8
Joined
Aug 4, 2006
Messages
357
Well, you wouldn't want to remove the location while it's still in the hashtable, or there would be no point in storing it. What you probably want to do is remove the location after you've loaded it and are done using it. To do that, you would do:
  • Set yourLoc = (Load (Key Target) of (Integer A) in DR_Hash)
  • Custom script: call RemoveLocation(udg_yourLoc)
 
Level 6
Joined
Sep 9, 2006
Messages
92
Dont forget to null the reference in the hashtable. Hashtable count references, and handleids only get freed when there are 0 references left.

not sure what your talking about here, but so when i clear a hashtable does that remove the locations saved in it also?

(but other points such as temp points still need to be removed with script)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
You do not null values in the hash table, you remove them (remove handle hash) so as to free the hash index.
Locations are not stored in the hashtable, only a pointer to the location is. WC3 was apparently made with OOP. Thus you want to remove the location which the hashtable refers to via the standard location removal script and then flush the index from the hashtable (to allow the handle index the location used to be recycled and to make sure the table functions at optimal efficency).
 
Level 6
Joined
Sep 9, 2006
Messages
92
You do not null values in the hash table, you remove them (remove handle hash) so as to free the hash index.
Locations are not stored in the hashtable, only a pointer to the location is. WC3 was apparently made with OOP. Thus you want to remove the location which the hashtable refers to via the standard location removal script and then flush the index from the hashtable (to allow the handle index the location used to be recycled and to make sure the table functions at optimal efficency).

So if my hash location saves say the offset of a temppoint then i removelocation temppoint and then clear the hashtable once im done with it?

also, remind me please, does saving a point to a variable and then saving a different point to the same variable leak? like save position of target to pointA then move the target then again save position of target to pointA without removing the first one

another question, if i dont use any temp points but instead save all the points into the hash does this mean there is no leaking or need to remove points? (besides clearing the hash once the spell, in this case, is over)
 
Level 9
Joined
Nov 28, 2008
Messages
704
So save your location, DO NOT REMOVE IT.

Load it, and when you are done with it, custom script it away.

Then flush your hashtable. I don't know the GUI put the JASS is FlushChildHashtable(hash, id).

To answer your last question, you need to use the custom script RemoveLocation() to remove the location from the hashtable. You cant just flush the hashtable and have it be auto destroyed as the hashtable doesnt have the actual location in it, just an integer representing a location in memory to it.
 
Level 6
Joined
Sep 9, 2006
Messages
92
To answer your last question, you need to use the custom script RemoveLocation() to remove the location from the hashtable. You cant just flush the hashtable and have it be auto destroyed as the hashtable doesnt have the actual location in it, just an integer representing a location in memory to it.

I dont understand what i would put into the removelocation for a hashtable location, unless im misunderstanding this. I save a point to a hashtable, and i clear the hashtable. Does this remove the point making it not leak?

maybe i should just post my version of my spell and have people look at the code directly and see if its actually leaking or not...
 
Level 8
Joined
Apr 30, 2009
Messages
338
you have to save the hash point as a temporary variable and then destroy that variable.

You only have to do this when you want the handle destroyed, so it's not like you're wasting a global during the whole trigger. Just put these lines at the end:

  • Set temp_point = Load Key(hash point) of Key(hash key) in Hashtable
  • Custom Script: call RemoveLocation(udg_temp_point)
  • Hashtable - clear all child hashtables of Key(hash key) in Hashtable
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Once again. . .
Hashtables store integers, strings, reals, booleans or pointers.

When you store a location handle in a hashtable, you are storing its 32 bit pointer and not the actual location object itself. Thus when you clear the hashtable, all you do is flush away a pointer to the location (and free up some space in the hashtable to make it more efficent). The location still remains in memory, and infact will be the forever unless you have another pointer to it or can get a pointer to it which you then pass through the location destruction native.

Remember that clearing hashtables of usless data is important. It keeps them working efficently and also allows the recycling of handleIDs (pointers). While a handle is still stored in a struct, it's index can not be recycled even if the object it points to has long since stopped existing.
 
Status
Not open for further replies.
Top