I have a question related to memory or app perform...
# getting-started
l
I have a question related to memory or app performance. Please suggest me which box of code 1 or 2 help me in less memory allocation or both will use same amount of memory. In first box I have used map and putting data in map inside cursor. In 2nd box I have used list of data class operation is performing as above. My app is working both condition but I am curious to learn that will 2nd box use same amount of memory because in 2nd box we are creating multiple instances of data class while in 1st box we are just inserting data in single instance of map. Thanks
j
I can't say which uses less memory, but I would not recommend using a map unless you need to perform a lookup by key. If for no other reason than readability
Also I'd look into if there's an easy way to convert your cursor to a sequence, then you can call .map and lose the while loop
l
Okay But today I used android studio profiler to check this and I found when I call this code memory size for kotlin/java go to 16.4 to 17 mb in both case but I am new to profiler so I don't know how to check this.
j
The map most probably uses a bit more memory: every entry is stored in an instance of Map.Entry (which basically is the same as your data class), and all the entries are stored in linked lists themselves stored inside an array of buckets. I concur with Jacob: if you need to lookup by keys, use a map. If you need an ordered list of records, use a list. Don’t choose based on what consumes more memory.
l
Ok I got it thanks to @Jacob and @jbnizet thanks a lot.