I found the primary cause of my memory leak. It was around executing a shell command by creating a Process object and opening up input and output streams. I used this to detect rooted devices. I'm not enough of an expert on the Process class to explain why this is causing leaks (I'm going to read up on it now), but if you're using code similar to this I'd be alert to this issue.
public static enum SHELL_COMMAND
{
check_su_binary(new String[] { "/system/xbin/which", "su" }), ;
String[] command;
SHELL_COMMAND(String[] command)
{
this.command = command;
}
}
/**
* @param shellCommand
* @return
*/
public List<String> executeCommand(SHELL_COMMAND shellCommand)
{
//this code was causing my memory leak
try
{
String line = null;
List<String> fullResponse = new ArrayList<String>();
Process localProcess = Runtime.getRuntime().exec(shellCommand.command);
OutputStreamWriter writer = new OutputStreamWriter(localProcess.getOutputStream());
BufferedWriter bufferedWriter = new BufferedWriter(writer);
InputStreamReader reader = new InputStreamReader(localProcess.getInputStream());
BufferedReader in = new BufferedReader(reader);
while ((line = in.readLine()) != null)
{
fullResponse.add(line);
}
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
bufferedWriter.close();
bufferedWriter = null;
writer.close();
writer = null;
in.close();
in = null;
reader.close();
reader = null;
}
catch (IOException e)
{
e.printStackTrace();
}
return fullResponse;
}