Memory leak with String[]?
Monkey Targets Forums/iOS/Memory leak with String[]?
| ||
Got some legacy code along these lines: Local file:String[] = app.LoadString(filename).Split("~n") file = file[1..] 'Skip header For Local dataline:String = EachIn file If dataline.Contains("//") Then Exit Local objstr:String[] = dataline.Split("~t") If objstr[0] = objid Return CreateMyObject(objstr) End Next Not especially pretty, but I've found that every time it's called, allocated memory increases by around 2mb and never goes back down. I'm aware that GC only kicks in every 8mb, but if I set the code to manually trigger by tapping the screen, I can tick up allocated memory indefinitely until the device crashes. I've checked in the profiler and all the memory is being allocated by Split/Slice. Anyone else encountered this? |
| ||
NB: the contents of objstr are NOT being retained by the CreateMyObject function, which is in any case only invoked once per call and could only ever retain a reference to a handful of bytes. Could it possibly be the repeated reallocation of the objstr[] array via Split that's letting memory escape? Update: I changed the loop to only split the line that matched the id - no change in behaviour. I removed the 'eachin' and replaced it with a simple numerical counter - no change in behaviour. Update: Checked on PC and no memory leak. Something different on iOS (at least) |