Android Question [Solved]Out of Memory?

Midimaster

Active Member
Licensed User
Sorry... the out of memory was not caused by the allocation, but because i did a mistake....

but my questions are still valid:


How does B4A handle the memory consumption of arrays? I often ReDIM my main array inside a SUB. Until now I had no problems with this.

B4X:
sub Globals
    Private MainArray(1000) as SHORT
    Public Converter As ByteConverter
end sub


Sub OftenUsedSub
    Dim locBytes() as Byte
    Stream.ReadBytes(locBytes,......
    Dim locArray() as Short = Converter.ShortsFromBytes(locBytes)
    ....
    MainArray=locArray
End Sub

As you see, I change the size of the array inside SUBs when receiving Bytes from Stream. Will this change the pointer? What will happen with the prior array content? Will this eat RAM, when I do it often?

Can I scan the remaining memory size to detect problems?
 
Last edited:

agraham

Expert
Licensed User
Longtime User
As you see, I change the size of the array inside SUBs when receiving Bytes from Stream. Will this change the pointer? What will happen with the prior array content? Will this eat RAM, when I do it often?
With managed code like Java and .NET you don't need to worry about memory management.
You get a new array with Dim and the variable is set to a reference to the new array.
Assigning one array variable to another array variable copies the reference from one variable to the other.
The old array is probably now orphaned, is not accessible as no references to it now exist, and it will be garbage collected and the memory reclaimed.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…