I'm currently writing a program in Java and it's been a long time since I've done any programming, and even longer since I've done any dynamic memory allocation, and longer yet since I've programmed in Java!
Can you please tell me: should I delete/free/etc dataBytes array, or should I leave it for garbage collection, or will it automatically delete/free the memory when it exits the myFunc() scope?
P.S. I realize that if myFunc isn't called frequently, memory will likely never be an issue but please humor me, as I know I will be using dynamic memory allocation much more in the future as my app gets closer to launch.
public void myFunc() {
byte[] dataBytes = null;
try {
// Open data file and read contents to byte array buffer
InputStream inputFile= parent.getAssets().open("myFile.txt");
dataBytes = new byte[inputFile.available()];
taxesFile.read(dataBytes);
taxesFile.close();
return;
} catch (IOException e) {
System.err.println("Failed to open myFile.txt");
e.printStackTrace();
}
}
Thanks for your help!