Search code examples
androidmemory-managementddms

Object creation tracking in Android DDMS, VM out of memory


Hey, I'm new to Android and kindly correct me if I'm wrong : I'm trying to monitor the number of objects created and heap used (which obviously depends on the number of objects) through DDMS. During this, if I start an application, I have 'n' no. of object created. Pressing back button will not necessarily call onDestroy() and hence the number of objects will still be somewhat equal to 'n'. Now, when I again launch the application, again onCreate() will be called and again those 'n' objects will be created (now total no. of objects will be more than 'n'). So, will repeating this process (relaunching the app) will cause a continuous increase in the number of objects ? (which obviously should not happen)


Solution

  • The number of objects will increase as they are created, then decrease as the garbage collector runs.

    If the number of objects continues to increase even with garbage collection, then you probably have a memory leak. The "hprof" heap dump (when can be triggered by clicking a button in DDMS) can help identify the cause.