Warcraft III resources & community, 2003–2006 · archived

Trying to understand potential leaks

7 posts
#1

Trying to understand potential leaks

I'm writing a stupidly complex set of jass scripts and tried to prevent as many leaks as possible. However, I'm concerned there's some really simple things that could leak. Like, is there a difference between the two test functions below?


function cache takes nothing returns gamecache
  return udg_mycache
endfunction

function testA takes string s returns nothing
  call StoreString(cache(), "something", "else", s)
endfunction

function testB takes string s returns nothing
  local gamecache g = cache()
  call StoreString(g, "something", "else", s)
  set g = null
endfunction


And what about ignoring return values? I remember seeing that parameters don't need to be nulled, but do returns?

For example, would this code leak?
call UnitRemoveItem(udg_a, UnitAddItem(udg_a, 'I000'))
#2
Second function will have less leaks.
#3
Leaks are saved "things" that are not being used, thus all they do is to take away memory.
So returned values would not "leak", because you do something with that.
Local variables have to be nullified, because even after the function is executed they stay the way they are.
Nullifying a variable means removing stored values from a variable.
call UnitRemoveItem(udg_a, UnitAddItem(udg_a, 'I000'))

There are no locals, or any "things" that are unused.
No leaks.
#4
Argh. The idea is not too strange, UnMi.

Who says, that a given parameter differs internally from a local variable?
What if these things whould really need to be nullified?

I mean - before I read about it, I whould never have guessed, that a pure variable can leak.

One may really want to think about, no?
It whould be an unpleasant happening, if it does happen.
#5
Argh. The idea is not too strange, UnMi.

Who says, that a given parameter differs internally from a local variable?
What if these things whould really need to be nullified?

I mean - before I read about it, I whould never have guessed, that a pure variable can leak.

One may really want to think about, no?
It is an unpleasant happening, if it does happen.
#6
Quit posting stuff twice

Quit posting stuff twice
#7
both functions wont leak

you only have to null a local if you DEFINE it as a local, so those extra lines in TestB just waste map size and processing space