HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

String Question

06-08-2006, 01:26 AM#1
Ragnarok X
You can avoid the string leak for setting it to null?
06-08-2006, 01:50 AM#2
The_AwaKening
Can't clean string leaks unfortunately.
06-08-2006, 06:21 AM#3
Blade.dk
And they are not very bad anyways. Unless you use a billion of randomly generated strings.
06-08-2006, 10:16 PM#4
Ragnarok X
Then i should leave the strings without setting its to null?
06-08-2006, 11:17 PM#5
weaaddar
I'd like to correct who ever brought up that crazed notion that strings leak.

They don't, they are cached. This is an optimization technique to make string comparisons faster, and to make codeing for gui people easier. Rather then instansiating new strings (and having to worry about them leaking), they are recycled.

Please don't worry about strings, worry about locations and groups. Those are your main leaks. You don't worry that your hero unit leaks do you? Of course not, because they are going to be used all game.

A common string like "Not enough gold." can be used upwards of hundreds of time in a melee game. Why create new ones and sentence them to death by egc (which only runs after the games over or under heavy strained circumstances) when you can keep that same one over and over again.
06-08-2006, 11:26 PM#6
Ragnarok X
Thank you all.

I don't know that about the strings, thank weaaddar.
06-09-2006, 03:34 AM#7
Vexorian
Issue is that it caches every string, even those you won't use again so in rare cases you can end up spending way more memory than you should.

This is fixed by changing the way the triggers that make that many strings work.

Of course that's not an alternative most of the times. So I'll recommend people not to care that much about strings.

But maybe something you are doing that is generating a unneeded strings can be changed in that case do so.

"In this example"
You want to remove all the vowels there are 2 ways to do it, you can keep adding the consonants to an empty string or you can loop till you find a vowel and then use indexes to add the non-vowel parts extracting them first as substrings.