Another Leak Question [RESOLVED]
Another Leak Question [RESOLVED]
If I were to set a variable (point) at map initialization, would it leak each time I made a reference to it? Or, can I just declare the variable and use it indefinitely without worrying much about leaks?
- Rising_Dusk
- Chosen of the Intargweeb
- Posts: 4031
- Joined: Sat Dec 15, 2007 1:50 pm
- Contact:
Re: Another Leak Question
It depends what you mean by a reference. If you reference the global location directly, you're fine, but if you reference it in the form of a local variable you'll have to nullify that local at the end of the function.
"I'll come to Florida one day and make you look like a damn princess." ~Hep
Re: Another Leak Question
I was using it for a global location, so I'm good.
A bonus tidbit too; thanks!
A bonus tidbit too; thanks!
Re: Another Leak Question
Wait, what? I thought you wouldn't have to because the local is using a reference to an object that still exists...Rising_Dusk wrote:It depends what you mean by a reference. If you reference the global location directly, you're fine, but if you reference it in the form of a local variable you'll have to nullify that local at the end of the function.
Last edited by Tupolev on Sat May 31, 2008 2:55 pm, edited 2 times in total.
- Rising_Dusk
- Chosen of the Intargweeb
- Posts: 4031
- Joined: Sat Dec 15, 2007 1:50 pm
- Contact:
Re: Another Leak Question
Consider the following:
You have to set f = null to recycle that handle pointer or else it will leak the 4 byte handle reference. There may be more to it than that, Vex would know, but as far as I'm aware this is the way of things. Let me ask Vex and get back to you, though.
Code: Select all
globals
unit u = CreateUnit(Player(0),'hfoo',0,0,0)
endglobals
function a takes nothing returns nothing
local unit f = u
//Blah
set f = null
endfunction
"I'll come to Florida one day and make you look like a damn princess." ~Hep
Re: Another Leak Question
What if you just create a unit by using 'local unit u = CreateUnit(parameters)'?
Does that need to be nulled if the unit doesn't get removed?
Both you a while ago and the tutorial on wc3campaigns stated that it doesn't.
Does that need to be nulled if the unit doesn't get removed?
Both you a while ago and the tutorial on wc3campaigns stated that it doesn't.
- Rising_Dusk
- Chosen of the Intargweeb
- Posts: 4031
- Joined: Sat Dec 15, 2007 1:50 pm
- Contact:
Re: Another Leak Question
I just asked PipeDream and Vex and this is what they said:
Vex's recommendation is the best, though.
Grim explains it best there, though the bytecode logic is still a bit tricky. I had Pipe explain it a little more technically afterwards, but it was too convoluted an explanation for my tastes. Basically, if you never, ever change the handle, you don't have to null it, but if you change it or destroy it anywhere, you have to null it everywhere.<Rising_Dusk> Vex, question.
<Rising_Dusk> If I have some global variable.
<Rising_Dusk> And I set a local handle variable to that global variable.
<Rising_Dusk> Do I have to nullify that local variable since a reference to the handle still exists in the global?
<Rising_Dusk> I'm under the impression I do, but I'm unsure.
<Vexorian> local handle variable
<Vexorian> ambiguity
<Rising_Dusk> I used a unit for an example.
<Rising_Dusk> In the pastebin thing.
<grim001__> if you never want to destroy that handle you never need to null it anywhere, if you want to destroy it at some point you must null it everywhere it was used unless it got overwritten
<PipeDream> assign any variable: old value refc--, new value refc++, don't refc modify if value is less than 0x100000
Vex's recommendation is the best, though.
<Vexorian> I always null locals.
"I'll come to Florida one day and make you look like a damn princess." ~Hep
Re: Another Leak Question
Aight, thanks. By looking through that and other stuff I beleive I get it much better now. The reference objects have a value attached to them, and get destroyed when the value is zero and they aren't referencing things, but unless you compensate for the bug here, the value won't decriment and will just go up, so when you destroy the handle and manage everything, the reference object thing won't destroy itself because it thinks it's still active because it's attached value isn't zero. And that you don't have to do this with things like player variables because the player variable will never be destroyed so it doesn't matter if that referencing object is incapable of decrimenting it's value.
Thx.
Thx.