I have an ArrayList
with more than 1000 string items in an Activity
. Number of members of ArrayList
does not change and no element update occurs. That Activity can be created and destroyed many times during application
life time, but also it may be a few times. Also, ArrayList
will be used to construct a ListView
. Now I have two approaches in about ArrayList
:
- setting its variable as static to avoid creating objects and initializing
ArrayList
each time inonCreate()
ofActivity
- creating and initializing
ArrayList
inonCreate()
ofActivity
to avoid memory leak
I do not know which way is better or is there any other way?