• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Trying to understand potential leaks

Status
Not open for further replies.
Level 3
Joined
Aug 17, 2006
Messages
38
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?

Code:
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?
Code:
call UnitRemoveItem(udg_a, UnitAddItem(udg_a, 'I000'))
 
Level 5
Joined
Feb 16, 2006
Messages
151
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.
JASS:
call UnitRemoveItem(udg_a, UnitAddItem(udg_a, 'I000'))
There are no locals, or any "things" that are unused.
No leaks.
 
Level 5
Joined
May 22, 2006
Messages
150
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.
 
Level 5
Joined
May 22, 2006
Messages
150
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.
 
Status
Not open for further replies.
Top