Android Question Map Limit

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

Just wondering if there is a limit on the number of events that a Map can have ?

I am loading events into a map using:

B4X:
Dim Map1 As Map
Map1.Initialize

Map1.Put("Key", "Value")

However, is there a limit on the number of events I can put before the app decides to force close, memory issues etc because there is to many items in the map ?

I haven't come across any errors yet but want to know if it will cause any errors if I keep loading items into the map.
 

aaronk

Well-Known Member
Licensed User
Longtime User
I do not understand what events you are referring.

What I am trying to say is if I use the following code and put it in the button_click sub:

B4X:
Map1.Put("Key", "Value")

How many times can I press the button before it crashes the app.

Yes I could put it in a loop to find out, but rather know if there is such limit or not.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
The limit is the available memory. Devices have different memory sizes, so there's no definitive answer to such a question. The space allocated to your Java app ranges from 16 MB on old devices to 512 MB or more on recent devices (with LargeHeap enabled).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Assuming that the strings that you put in the map are not too large then you will most probably never hit any limit.

Even if the user presses on the button 100k times then the memory required for this map is quite small:
100,000 * (5 * 2) [two strings with 5 characters] * 2 [each character requires 2 bytes] * 1.5 [unrealistic 50% overhead for the Map pointers and other small stuff] = 3mb.

Similar to the memory required for a single medium+ image.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Are you using the same key each time?
No, a new key and value is created each time.

Seems that what I am trying to do will be fine and won't crash the app.
Thanks all for your help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…