• 🏆 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!

Does this leak?

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

Suppose I have a location stored that is accessed by an array call.

This location gets used multiple times in a function. So I set a local variable to it to save some time.

After the function is done, do I need to remove the local location, or only null it, assuming I plan to keep the location in the array always.

From Vexorian's jass manual:

all handle arguments (and handle subtypes) have roughly pass-by-reference semantics. In other words, modifying the "internals" of a handle variable, like a unit, passed to a function as an argument will alter the variable both within the callee function and the caller

I would guess I would not destroy it, otherwise it would also destroy the value held in the array as well? I have doubts only because Vexorian calls it "roughly pass-by-reference."



JASS:
...
local location myLoc = locations[i]
...
call RemoveLocation(myLoc) //should I make this call?, my gut says no
set myLoc = null
 
Level 25
Joined
Sep 26, 2009
Messages
2,383
location points at some handle of type point.
"myLoc = location" means that myLoc now points at what location is pointing, thus they both point at the same handle.
If you destroy myLoc, you destroy what both the array and variable point at.

What's happening with the handle? Does it change some of its attributes or whatever else? Doesn't matter, since its ID is so far still the same, so the array/variable still points at the very same handle, no matter how much that handle changes.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Right that is what I thought, but I wanted to verify.

So why does Vexorian say "roughly" pass-by-reference semantics?

Are there any handle types which don't have pass-by-reference semantics?
 
Level 25
Joined
Sep 26, 2009
Messages
2,383
not sure if there are such handles, but there are non-handles that just copy the value of other variable. Non-handles are integer, real, boolean, strings... afaik these are the only ones, maybe there's few more like unit type which is I think just an integer number, etc.

Handles: variables behave like pointers (pointer logic)
Non-handles: variables use assignment statements (if I have x = 5 and next statement is y = x and none are pointers, then y will get the value x had when the statement was carried out)

At least that's how I see things working and I wasn't proven wrong yet. If anyone knows better, he may clarify.
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
Non-handles should pass by value as expected.

I was just curious if there was a subtle difference between JASS pass-by-reference semantics and standard programming (e.g. Python, Java, etc.).

That's what it looks like he was hinting, but I guess it's so subtle the end behavior is the same.
 
Status
Not open for further replies.
Top