java - Memory Leak - Writing to files in a loop -


i new android development , i'm having trouble debugging memory leaks. have tried using memory allocation tracking tool on android studio , found this... memory allocation tracking tool

using tool pointed majority of memory allocation come line:

string datajson = datamapasjsonobject(data).tostring() + "\n"; 

and one:

outputstreamwriter writer = new outputstreamwriter(stream); 

keep in mind, code ran in loop, approximately once every second. here full code below... pointers appreciated.

private void savedata(datamap data) {     log.d(tag, "savedata");     if (!isexternalstoragewritable()) {         log.d(tag, "external storage not writable");         return;     }     file directory = environment.getexternalstoragepublicdirectory(environment.directory_documents);     directory.mkdirs();     file file = null;     if (data.containskey("counts")) { // pretty bad way of doing this..         file = new file(directory, "acc_count_data.txt");     } else {         file = new file(directory, "wearable_data.txt");     }      log.d(tag, "trying log file: " + file.getpath());      string datajson = datamapasjsonobject(data).tostring() + "\n";     try {         fileoutputstream stream = new fileoutputstream(file, true);         outputstreamwriter writer = new outputstreamwriter(stream);         writer.write(datajson);         writer.close();         stream.close();      } catch (exception e) {         log.d(tag, "error saving");         e.printstacktrace();     } } 

thank you!


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -