The app is pretty basic, it allows the users to fill out the surveys and then it sends them to the server. I have setPersistence enabled so it will also work while they are offline and it just sends them to the server when online.
This works fine, however after a certain number of surveys (30-50) the app crashes each time on start with com.google.android.gms.dynamite_dynamitemodulesc
error. All of them are reported as different errors due to memory address in the name. The explanation for the error is
Caused by java.lang.OutOfMemoryError Failed to allocate a 202 byte allocation with 15532496 free bytes and 14MB until OOM; failed due to fragmentation (required continguous free 16384 bytes for a new buffer where largest contiguous free 12288 bytes)
The issue is that after the surveys are sent, they are not removed from local memory for some reason. So even though the app is fully in sync and nothing is accessed locally, the cache isn't cleared.
I was looking for a way to manually clear the Firebase cache, but as far as I see it's not possible.
Here is how the data is stored at the end of the session (pretty basic). I'd like to point out again that this data isn't accessed after this is done, which is why I figured it should clear the cache once it syncs it with the server.
DatabaseReference session = mResults.push();
session.child("examiner").setValue(username);
session.child("place").setValue(place);
session.child("filled_by").setValue(fillingOut);
session.child("timestamp").setValue(millis);
session.child("ref_number").setValue(referenceCode);
DatabaseReference questions = session.child("questions");
for(Question q : allQuestions) {
DatabaseReference question = questions.push();
question.child("question").setValue(q.text);
question.child("skipped").setValue(q.skipped);
DatabaseReference answers = question.child("answers");
for(Answer a : q.answers) {
DatabaseReference answer = answers.push();
answer.child("selected").setValue(a.selected);
answer.child("text").setValue(a.text);
answer.child("value").setValue(a.inputValue);
}
}