| 12-30-2006, 02:24 AM | #1 |
Hi: This is a doubt that I have about memory leaks. I have this example trigger. JASS:function ItLeaks?? takes group g returns nothing local group g1 = g // <Do my stuff here> call DestroyGroup(g1) set g1 = null endfunction The question is: If I destroy and nullify g1, then g will be nullified too??? |
| 12-30-2006, 02:30 AM | #2 |
No; g should not be destroyed. You've denoted g1 to have the VALUE of g; not to link to g itself. It's a one time deal; copy the value; then the variables act as if they have never met. Whatever happens to g1; g doesn't care because nothing happens to g when g1 is altered. Atleast that is to the best of my knowledge, as a programmer who doesn't know Jass. |
| 12-30-2006, 02:41 AM | #3 |
The group G will also be destroyed. Groups are handles as you know, which 'point' to an object. It's like removing a unit. Once it's removed, any unit variable with the value being that unit will be nothing. When a parameter is passed to a function, a copy of it is made, so what you do doesn't actually affect the variable you passed itself. So, nulling the variable doesn't null a variable you might have passed as a parameter. |
| 12-30-2006, 09:41 AM | #4 |
g1 is set to the value of the variable g, which means it has the same value. That 4 byte value is a pointer to an object (the group), so if you destroy g1, you destroy g. However, all local variables must be nullified (or left pointing at a permament handle) to avoid a leak. Passed variables do not require nullifying though, as they appear to decrement correctly. |
| 12-30-2006, 05:38 PM | #5 |
Ah, I seem to be incorrect then. My appologies. |
| 12-30-2006, 06:23 PM | #6 |
So when I do local group g1 = g the thing that I'm doing is like a link to the handle "pointer" (I dont know if this is the right word), in other words, g and g1 make reference to the same data, not a data copy. I'm doing this question because I'm working with timers, and I was looking Blade.dk Stomp spell tutorial, where he uses the timers. There he declare the timer as a local variable in the main code, and then in the timer code he destroy that variable. Thanks for your help. |
| 12-31-2006, 09:47 AM | #7 |
It's a link not a copy, as you allready mentioned, and if you destroy the link, the whole thing behind will be destroyed (in case of a handle). For timers, there are serious problems with timers setting to null. If you are going to use timers heavily, I would say you should use a timerstack (DL the latest CS, it includes one) |
