B4J Question Possible bug

npsonic

Active Member
Licensed User
This code will give exception java.lang.OutOfMemoryError: Java heap space
How is that possible or do I not understand something?

B4X:
Dim s As String = File.ReadString(File.DirApp, "lorem.txt")
    
Do While s.Length > 0   
    s = s.SubString(1)
Loop

File used for test is just 100 KB of lorem ipsum
 

stevel05

Expert
Licensed User
Longtime User
Strings are Immutable, therefore every time you make a change to it, it creates a new string object. I would guess that creating 100000 new string objects in short order is overwhelming the garbage collector as there is no time in between the iterations for it to run.
 
Upvote 0
Top