| 09-17-2007, 11:53 PM | #1 |
How do you stop a group from leaking if you have to return it? In local form. For example... g is a local group variable Code:
return g The trigger ends there, yet g must still exist. Or will returning g pass the same exact value which can be destroyed later? |
| 09-18-2007, 12:54 AM | #2 |
you can use a global, or a variant of a return bug to convert the group to an integer, and then return the integer as a group. I recommend the first option over the second. |
| 09-18-2007, 01:19 AM | #3 |
So it will leak? How will using globals change that? Without leaving the function of course... How about WantDestroyGroup? |
| 09-18-2007, 02:00 AM | #4 |
Pass the group as an argument to the function and don't return it. Think GroupEnum. |
| 09-18-2007, 02:01 AM | #5 |
Nononono. Ammorth misunderstood. The part that is leaking is not the pointer, but the group. The same old rule still applies - you need to destroy the group when you're done with it. If that's in a different function than the one the group was created in, so be it. Oh, just now read the last part of your post. The answer to your last question would be yes. Edit: Pipe, what's wrong with returning it? He's still going to have to destroy it either way. |
| 09-18-2007, 05:43 AM | #6 |
returning it leaks the pointer. |
| 09-18-2007, 06:15 AM | #7 |
I assumed he meant the variable g was leaking, not the actual group, since he was returning the group, which would mean he would be using the group in the calling function, hence not losing it. What pipe means is doing something like: JASS:function GroupFunc takes group g returns nothing //Do stuff with g endfunction function YourFunc takes nothing returns nothing local group g = CreateGroup() call GroupFunc(g) //Do stuff with g call DestroyGroup(g) set g = null endfunction The engine will clean arguments of a function, so passing a handle will clean itself. Of course, you could implement this multiple ways, this is only an example. |
| 09-18-2007, 04:59 PM | #8 |
I always learned that if you returned a variable, then war3 cleaned up its pointer, so you don't have to null it. Is this an exception to the rule or am I wrong? |
| 09-18-2007, 05:05 PM | #9 |
as a general rule wc3 doesn't do ANYTHING smart like that returning just means that the pointer have moved you still need to null it in the returned function |
| 09-18-2007, 05:53 PM | #10 | |
Quote:
Local pointers (variables in war3) only exist within the function they were created in. The actual data being pointed to can be retrieved in another function, but not the actual pointer. So uhhh I'm going to have to disagree with you on this one :). |
| 09-18-2007, 06:37 PM | #11 |
ok fine :/ returning just means that the pointer VALUE has moved you still need to null it in the returned function forgot a word :/ |
| 09-18-2007, 07:19 PM | #12 | ||
Quote:
Taken from Pipedreams tutorial on Local Var Leaks: Quote:
|
| 09-18-2007, 07:24 PM | #13 |
like I said wc3 doesn't ever do anything smart :/ |
| 09-18-2007, 07:34 PM | #14 |
Thanks Alex, I'm surprised that I've never known that. Although I guess there aren't really many times when not knowing that would have hurt me. |
| 10-08-2007, 02:39 AM | #15 |
So I can't return a group without leaking? I'm making a script called 'GetUnitsOfRelation', it's meant to be standalone. WantDestroyGroup would not work? |
