Another Leak Question [RESOLVED]

This is where all discussion of WC3 mapmaking should be held. This forum exists particularly for mapmaking needs. If you have a question on how something works or have need for some code review, this is the place to put it.
Locked
Hydrolisk
Keeper of the Keys
Posts: 408
Joined: Mon Feb 25, 2008 2:25 am
Location: Canada

Another Leak Question [RESOLVED]

Post by Hydrolisk » Sat May 31, 2008 1:16 am

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?
Image

User avatar
Rising_Dusk
Chosen of the Intargweeb
Posts: 4031
Joined: Sat Dec 15, 2007 1:50 pm
Contact:

Re: Another Leak Question

Post by Rising_Dusk » Sat May 31, 2008 1:26 am

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

Hydrolisk
Keeper of the Keys
Posts: 408
Joined: Mon Feb 25, 2008 2:25 am
Location: Canada

Re: Another Leak Question

Post by Hydrolisk » Sat May 31, 2008 1:32 am

I was using it for a global location, so I'm good.

A bonus tidbit too; thanks!
Image

Tupolev
Noobite Warrior
Posts: 15
Joined: Wed Jan 16, 2008 4:13 am

Re: Another Leak Question

Post by Tupolev » Sat May 31, 2008 2:23 pm

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.
Wait, what? I thought you wouldn't have to because the local is using a reference to an object that still exists...
Last edited by Tupolev on Sat May 31, 2008 2:55 pm, edited 2 times in total.

User avatar
Rising_Dusk
Chosen of the Intargweeb
Posts: 4031
Joined: Sat Dec 15, 2007 1:50 pm
Contact:

Re: Another Leak Question

Post by Rising_Dusk » Sat May 31, 2008 2:52 pm

Consider the following:

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
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.
"I'll come to Florida one day and make you look like a damn princess." ~Hep

Tupolev
Noobite Warrior
Posts: 15
Joined: Wed Jan 16, 2008 4:13 am

Re: Another Leak Question

Post by Tupolev » Sat May 31, 2008 2:54 pm

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.

User avatar
Rising_Dusk
Chosen of the Intargweeb
Posts: 4031
Joined: Sat Dec 15, 2007 1:50 pm
Contact:

Re: Another Leak Question

Post by Rising_Dusk » Sat May 31, 2008 3:01 pm

I just asked PipeDream and Vex and this is what they said:
<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
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.

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

Tupolev
Noobite Warrior
Posts: 15
Joined: Wed Jan 16, 2008 4:13 am

Re: Another Leak Question

Post by Tupolev » Sat May 31, 2008 3:15 pm

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.

Locked

Return to “Custom Map Creation”