1

They are various ways mentioned in this stackoverflow question:How can I determine if my android app has memory leak?

Is StrictMode good to detect memory leak in android for should we depend on tools. StrictMode

public void onCreate() {
     if (DEVELOPER_MODE) {
         StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                 .detectDiskReads()
                 .detectDiskWrites()
                 .detectNetwork()   // or .detectAll() for all detectable problems
                 .penaltyLog()
                 .build());
         StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                 .detectLeakedSqlLiteObjects()
                 .detectLeakedClosableObjects()
                 .penaltyLog()
                 .penaltyDeath()
                 .build());
     }
     super.onCreate();
 }
Community
  • 1
  • 1
Ashish Rathee
  • 449
  • 3
  • 16
  • Possible duplicate of [How can I determine if my android app has memory leak?](http://stackoverflow.com/questions/11064940/how-can-i-determine-if-my-android-app-has-memory-leak) – The SE I loved is dead Oct 19 '16 at 16:59
  • @dorukayhan I already mentioned in question this question arises while reading that question.... So how it can be duplicate. – Ashish Rathee Oct 19 '16 at 17:02

1 Answers1

0

StrictMode documentation does not mention anything about memory so it probably does not. The documentation describes some (not absolute) protection against disk reads/writes, network access, etc. The only memory mentioned is flash memory which is different from RAMemory.

Moreover, automated detection of a memory leak is a difficult problem. A object hangs around because that object has a path of pointers to itself starting from a GC Root (ex: a pointer starting from a thread's stack). This article does a good job of covering the problem (http://www.w3resource.com/java-tutorial/garbage-collection-in-java.php). The garbage collector doesn't know if an edge along that path is safe to remove. That's where you come in. You bring in your knowledge of how the application should run and find pointers/edges that shouldn't be there.

Your best bet for diagnosing a memory leak is to use existing articles on how to diagnose memory leaks like How can I determine if my android app has memory leak? . There are many other free tools you can use like visualvm and jhat. Good luck!

Community
  • 1
  • 1
joseph
  • 2,429
  • 1
  • 22
  • 43