All terms of all language in memory

More
7 years 6 months ago - 7 years 6 months ago #2282 by jeauger
Hi,
While profiling the application I saw that all terms of all language are in memory. We have 8 languages in our game and it represents almost 1MB of Strings in memory (and the game is not done yet). Is there a way to only allocate the terms of the current language (in our case the current language is always the device language and you cannot switch language)?

Also, as I said, I saw with the profiler that I2Localization instantiates 1MB of strings but when I profile the memory with Xcode Instrument it takes more than 3MB. Do you have an idea of what can be the missing 2MB?
Last edit: 7 years 6 months ago by jeauger.

Please Log in or Create an account to join the conversation.

More
7 years 6 months ago #2284 by Frank
Hi,
I'm working on reducing the memory needed, by only loading the language that is currently shown, but while that solution is finished, you could do one of this things:

The easiest is to call this method from any of your scripts, it will remove all the strings that are not used, and will free that memory:
		void Start()
		{
				FreeUnusedLanguages();
		}

		public static void FreeUnusedLanguages()
		{
			var source    = LocalizationManager.Sources[0];
			int langIndex = source.GetLanguageIndex(LocalizationManager.CurrentLanguage);

			for (int i=0; i<source.mTerms.Count; ++i)
			{
				var term = source.mTerms[i];
				for (int j=0; j<term.Languages.Length; j++)
				{
					if (j != langIndex)
						term.Languages[j] = term.Languages_Touch[j] = null;  // free the strings memory
				}
			}
		}


Another way, is to separate the languages in different LanguageSources, and add them to the Global Sources array, that way you only load whats needed. But that way doesn't work always for editing, The way I'm working now is similar to this, but fixing those issues.

Hope that helps,
Frank

Are you :-) Give I2L 5 stars!
Are you :-( Please lets us know how to improve it!
To get the betas as soon as they are ready, check this out

Please Log in or Create an account to join the conversation.

Time to create page: 0.135 seconds
Template by JoomlaShine