In my app users can download, watch and delete 3d-objdata (*.obj) in runtime.
To generate the meshes on the fly, I heavily deal with strings.
My problem is, that these strings never get released by GarbageCollector and soon or later the app crashes (“ApplicationDidReceiveMemoryWarning”).
For further testing I wrote a very basic code that simply reads text from file into a string.
Setting this string to null or “” and reading from file again doubles up used memory. This is not covered by the Unity profiler, you only see it in XCode.
It’s not generally considered good practice, but if you’re reading huge amounts of data into strings and not dereferencing in between, you may not be getting a GC cycle triggered (or not cleaning them up). This gets compounded if you do thinks like concatenating strings, etc, because those create new copies of the string in memory.
One thing you should probably try is using a StringBuilder to work with your strings if possible to ease that pain if you’re concatenating strings. If you’re just working with a large string that’s getting crated and recreated, it may be necessary to force a garbage collection between by calling GC.Collect();