| 05-12-2009, 03:10 PM | #1 |
Hi, I am new with vJass structs and I have some question regarding the .destroy() function if it is attached to a handle. So here is my code: JASS:struct MyStruct unit victim endstruct function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing local MyStruct data = MyStruct.create() if(data.victim == null) then call BJDebugMsg("null") else call BJDebugMsg("OK") endif set data.victim = gg_unit_h000_0004 if(data.victim == null) then call BJDebugMsg("null") else call BJDebugMsg("OK") endif call data.destroy() if(data.victim == null) then call BJDebugMsg("null") else call BJDebugMsg("OK") endif endfunction The function will return null, OK, OK when triggered. Does this mean that the struct members are not nullified after the struct was destroyed? If that is the case, wouldn't it cause memory leaks? And how do you nullify the struct members if it is necessary? |
| 05-12-2009, 03:26 PM | #2 |
JASS:struct MyStruct unit victim method onDestroy takes nothing returns nothing set .victim = null endmethod endstruct |
| 05-12-2009, 03:48 PM | #3 |
You don't need to null structs members because they are just global arrays (once it's compiled). However, if you have something that checks if they are null, you may want to null them in the onDestroy method. |
| 05-12-2009, 04:04 PM | #4 |
so onDestroy method is some kind of special method that runs automatically when the struct instance is destroyed? |
| 05-12-2009, 04:35 PM | #5 |
yes |
| 05-12-2009, 04:53 PM | #6 |
Ok, thanks guys |
