I'm having a problem with the Android Garbage Collector and was hoping someone could point out what I may be doing wrong here. I have a lot of data at the start of my program that is generated and thrown into an ArrayList. Example of what I'm doing below...
m_aUnitsPhysical.add(new UnitData("P01", 1, 0, 0, false, false, 300, UnitType.PHYSICAL, 1, "Unit Name"));
There's about 236 of these statements in my class constructor. The array is defined as:
private ArrayList<UnitData> m_aUnitsPhysical; // Physical array listing
And in case it helps, the class constructor is...
public UnitData(String p_szID, int p_iAtk, int p_iDef, int p_iUp, boolean p_bLoot, boolean p_bHonor, int p_iCost, UnitType p_Type, int p_iLevel, String p_szName)
UnitData is a class of mine that simply stores the data, kinda like the old C struct. I know I'm chewing up huge amounts of memory during this operation. When it completes however, the Garbage Collector (as shown in logCat) kicks in and free's up huge amounts of data.
So, what's going on? Is the garbage collector angry with the way I'm doing the above statement, or is it telling me it's killing off memory from other applications? Is there any way to tell? Is there a better way of doing what I'm doing above that won't use so much memory? Should I try and use the SqlLite database instead of doing it this way?
I rarely get reports from my users that they've run into a memory issue, but they are occurring. Predominantly its when they leave the app for some reason or another then come back to it; the data in the array dissapears. I'm just trying to get a handle on how I should be doing this in case I'm doing it wrong. Any insight would be greatly appreciated!