| 01-16-2008, 08:33 PM | #1 |
i have readen that string leaks. But how exactly ? If you use it in a display message ? In an other function also ? If i do that : JASS:call BJDebugMsg("test") call BJDebugMsg("test") It will leak two times or only one time ? JASS:globals string S="test" endglobals function Hello takes nothing returns nothing call BJDebugMsg(S) endfunction will it leak ? In general can we solve a string leak ? |
| 01-16-2008, 08:36 PM | #2 |
As far as I know, leaks only occur when a variable is set and not cleaned up. For example, using something like set point = somepoint and then not following up with call RemoveLocation(point) or something. So I'd only say that S would not leak until you changed it. |
| 01-16-2008, 09:21 PM | #3 |
I may be mistaken but there is no native to destroy/remove strings. You can set the string to null but the variable/?pointer? still exists, and thats the problem. |
| 01-16-2008, 09:37 PM | #4 |
Strings don't really leak. However, War3 stores every string you use to memory for fast access later. There's nothing you can do about it, and not really much reason to, so don't worry about it. |
| 01-16-2008, 10:40 PM | #5 |
Strings aren't normal objects, they aren't destroyable, so yes in a way they do leak. I believe in WarCraft if you have a thousand BJDebugMsg that display the text "Hello World!" it will only be referencing a single string, rather than creating multiple strings with the content "Hello World!". In a sense, they leak, and there's nothing you can do about it. |
| 01-16-2008, 11:42 PM | #6 |
What about having only one string that stores everything and displaying only parts of it? |
| 01-16-2008, 11:47 PM | #7 |
When you use SubString() you make a new string so there is no point in doing so. Also, when you do StringA+StringB // "Hello " + "world!" it will make a new string "Hello world!" |
| 01-17-2008, 12:00 AM | #8 | |
Quote:
|
| 01-17-2008, 09:41 AM | #9 |
ok, anyway it must be a very little leak |
| 01-17-2008, 02:28 PM | #10 |
just don't do: JASS:loop exitwhen i == 10000 call BJDebugMsg(I2S(GetRandomInteger(-100000, 100000))) set i = i + 1 endloop which creates random, un-needed strings that will slowly fill up memory. |
| 01-17-2008, 02:56 PM | #11 | |
Quote:
And just why i will do that ? :p Ive understand how a string leak thx all |
| 01-17-2008, 03:03 PM | #12 |
the most important thing is: yes they leak, once, but it's effect is so lesser that it's very hard to notice, but, if you do what Ammorth coded, then you probably will notice something. |
| 01-17-2008, 03:30 PM | #13 |
so its always better to use constant strings (if possible) than randomly created strings? |
| 01-17-2008, 03:49 PM | #15 |
of course but i you can use constant string you dont need random o_O. and btw you need random string for what exactly ?! |
