Iv'e coded a ObjectLoader that takes a .obj file and it gives me what i want. My problem is that when handling big files(not even that big, about 80kb) i eventually end up with not getting all information because it stops reading after a while.
I get this in my LogCat before im done and debuger simply moves on to next method:
DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 2076 objects / 124280 bytes in 50ms
DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 4 objects / 232 bytes in 52ms
DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 142 objects / 46728 bytes in 49ms
DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 0 objects / 0 bytes in 53ms DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 533 objects / 63504 bytes in 39ms
DEBUG/dalvikvm(25743): GC_FOR_MALLOC freed 4 objects / 216 bytes in 50ms
DEBUG/dalvikvm(25743): GC_EXTERNAL_ALLOC freed 132 objects / 26768 bytes in 40ms
In other words, alot of Garbage Collection i guess. Is it simply because i allocate to much memory in my code? And if so, is there any basics I need to read into or do you have any other suggestions? I'm using 4 Vectors each ending up holding about 2K-3K objects. Edit: There's acctually 7 vectors, 3 extra for carrying indexes, but still i don't think it's that much.
private void readObj(InputStreamReader in) throws IOException
{
BufferedReader reader = null;
String line = null;
reader = new BufferedReader(in);
while ((line = reader.readLine()) != null)
{
Log.v(TAG, line);
if (line.startsWith("f"))
{
faces++;
processFLine(line);
} else if (line.startsWith("vn"))
{
normals++;
processVNLine(line);
} else if (line.startsWith("vt"))
{
UVCoords++;
processVTLine(line);
} else if (line.startsWith("v"))
{
vertices++;
processVLine(line);
}
}
}
private void processVNLine(String line)
{
String[] tokens = line.split("[ ]+");
int c = tokens.length;
for (int i = 1; i < c; i++)
{
_vn.add(Float.valueOf(tokens[i]));
}
}
private void processFLine(String line)
{
String[] tokens = line.split("[ ]+");
int c = tokens.length;
if (tokens[1].matches("[0-9]+"))
{
caseFEqOne(tokens, c);
}
if (tokens[1].matches("[0-9]+/[0-9]+"))
{
caseFEqTwo(tokens, c);
}
if (tokens[1].matches("[0-9]+//[0-9]+"))
{
caseFEqOneAndThree(tokens, c);
}
if (tokens[1].matches("[0-9]+/[0-9]+/[0-9]+"))
{
caseFEqThree(tokens, c);
}
}
private void caseFEqThree(String[] tokens, int c)
{
for (int i = 1; i < c; i++)
{
Short s = Short.valueOf(tokens[i].split("/")[0]);
s--;
_vPointer.add(s);
s = Short.valueOf(tokens[i].split("/")[1]);
s--;
_vtPointer.add(s);
s = Short.valueOf(tokens[i].split("/")[2]);
s--;
_vnPointer.add(s);
}
}
As you all said, it wasn't the garbage collectors fault. It was the LogCat's fault. And not the fact that it printed out those line about the garbage collecting, it's about the fact that it didn't print out my Log.i(tag, string) that I used when the loop was finished. (During the loop I used Log.v(). So it did in fact not give me incomplete result, I just wasn't able to see the full result or that it actually finished.