HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Nulling, again omg.

10-23-2007, 11:30 AM#1
cohadar
Quote:
Originally Posted by Vexorian
Not nulling handle local variables DOES leak memory, there is a 4bytes place holder in the place of the removed handle.

Now I know handles occupy 4 bytes,
but not nulling them does not mean that local reference memory is not freed after function ends.

Is there any solid proof of this claim?
10-23-2007, 11:56 AM#2
Toadcop
no Vex is joking

i allready told u =) if it's a CONSTANT object so there it's doesnt leak anything...
and you allreadysad the only TRUE fact it will simple not free the used handle (as index) so the number fo used handles will increse. == leak O.O

// i have tested this myths alot so you can trust me xD and don't waste time on it.
10-23-2007, 12:12 PM#3
Alexander244
This is what I understand from reading stuff people have posted over the years:
  • Every handle has a structure, which contains a pointer to the handle and a reference count.
  • The reference count is incremented whenever the handle is assigned to a local/global variable.
  • The reference count is decremented when a local/global pointing to it is reassigned to something else (including null).
  • It is not decremented when a function containing a local ends, which is why we set to null.
  • If we don't null locals, the reference count will never hit zero, so the structure will never be deallocated.
  • The position in the memory is therefore presumably still reserved by the game. (?)
10-23-2007, 02:13 PM#4
Toadcop
Quote:
If we don't null locals, the reference count will never hit zero, so the structure will never be deallocated.

The position in the memory is therefore presumably still reserved by the game. (?)
fasle it's counts on;y for the handle self. not for structure beyond. the structures are removed well in any situations.

omg well simple to say u are wrong. (and you are not the only one) don't read crap on forums just test it self ! =\
10-23-2007, 02:14 PM#5
Vexorian
Quote:
Originally Posted by Toadcop
no Vex is joking

i allready told u =) if it's a CONSTANT object so there it's doesnt leak anything...
and you allreadysad the only TRUE fact it will simple not free the used handle (as index) so the number fo used handles will increse. == leak O.O

// i have tested this myths alot so you can trust me xD and don't waste time on it.
Thanks for missing all the topic, this is nothing about "CONSTANT OBJECTS!!!11"

When you call RemoveHandle() The handle is destroyed, this freeds memory used by that object. But since there are still references to that object and blizzard didn't want to make access violations even more probable than they are now they place an empty holder in that address. Easy?



"proof"

Collapse JASS:
function aaa takes nothing returns nothing
 local location loc=Location(0,0)
    call RemoveLocation(loc)
endfunction



Run it periodically and frequently, watch memory usage raise...

Sure it also prevents handle id recycling and that slows the game down probably a much worse effect than the memory usage (which is just 4bytes, most handles should take much more than that), unless you really do this plenty of times...

--
Edit: Also, if you use typecasts to store pointers and make sure to clean all of a handle's references after destroying it, then try using a normal native on the restored reference, it would crash. On normal circunstances with the placeholders in action it will just do nothing.
10-23-2007, 02:30 PM#6
cohadar
Well those "referece struct" are inside jass virtual machine implementation,
and it seems strange that someone would make a condition that local variables implementation structs will not get recycled unless they are nulled,
that would mean that local integers need to be nulled as well and that is just too lame to be truth.

I presume PipeDream could shed some more light on this subject hmmmm?

EDIT:
Have seen that placeholder thing just now...
ZOMFG.. blizzard sux balls so hard.

I wonder why they even bothered implementing that feature when GUI does not even clean leaks, let alone nulls locals...
10-23-2007, 02:32 PM#7
Vexorian
Quote:
Well those "referece struct" are inside jass virtual machine implementation,
and it seems strange that someone would make a condition that local variables implementation structs will not get recycled unless they are nulled,
that would mean that local integers need to be nulled as well and that is just too lame to be truth.

It is not strange, it is a bug. Arguments don't do that.

I don't see why would this imply integers need to be nulled.
10-23-2007, 02:41 PM#8
cohadar
One question, are those unnulled references all pointing to the SAME placeholder or they all have their own?
10-23-2007, 02:50 PM#9
Vexorian
If the references used to point to the same handle they would then point to the same place holder.
10-23-2007, 03:32 PM#10
cohadar
Again it does not make sense, if I wanted to make my virtual engine crash resistant I could simple make all references point to same placeholder and it would all be ok, it is a concept of NULL class.

bugs bugs bugs....

EDIT:
arguments eh.
Collapse JASS:
private function Actions takes nothing returns nothing
    call SetUnitUserData(GetTriggerUnit(), GetUnitUserData(GetTriggerUnit()) + 1)
endfunction
So this should function will never increase reference counts?
10-23-2007, 04:38 PM#11
Toadcop
Quote:
bugs bugs bugs....
Blizz suck suck suck. as for my i know that. SC2 looser game the best guys have quited Blizzard.
wc3 is the last normal game (with some content)

+ you must don't care about and trying to avoid such stupid situation. (bugs)
well the current problem in truth is not a problem... ^^
10-23-2007, 07:20 PM#12
Pyrogasm
Quote:
Originally Posted by cohadar
EDIT:
arguments eh.
Collapse JASS:
private function Actions takes nothing returns nothing
    call SetUnitUserData(GetTriggerUnit(), GetUnitUserData(GetTriggerUnit()) + 1)
endfunction
So this should function will never increase reference counts?
It will not increase reference counts, but what Vexorian meant specifically is that this will never do so either:
Collapse JASS:
private function Actions takes unit U returns nothing
    call SetUnitUserData(U, GetUnitUserData(U) + 1)
endfunction
10-23-2007, 10:48 PM#13
PitzerMike
Collapse JASS:
function aaa takes location dummy returns nothing
  set dummy=Location(0,0)
  call RemoveLocation(dummy)
endfunction

Fixed?
10-23-2007, 11:12 PM#14
Pyrogasm
Yes.
10-24-2007, 06:34 AM#15
cohadar
Tutorial ffs

Anyways I finally understand that reference structs,
it is quite smart thing actually, it prevents jass scripts from directly accessing in-game memory, and since every reference must have a reference struct,
the higher reference count is, the laggier the game will be, it does not matter if you use gamecache or not.

I just hope those noobs in blizzard did not implement linear algorithm for recycling...