sangmingming / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

Memory leak when opening many activities in single test #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Run a test that loops and repeatedly opens and closes new activities
2. Log output of Debug.getNativeHeapAllocatedSize() each time
3. The memory used keeps increasing and will eventually crash the app

The ActivityUtils class has the LinkedHashSet<Activity> activityList member 
that keeps references to the closed activities. I tried adding in my loop a 
call to this new ActivityUtils method I threw together and the memory is gone.

    public void finishInactiveActivities() {
        // Finish all inactive activities
        for (Iterator<Activity> iter = activityList.iterator(); iter.hasNext();) {
            Activity a = iter.next();
            if (a != getCurrentActivity()) {
                finishActivity(a);
                iter.remove();
            }
        }
    }

Original issue reported on code.google.com by bjackson...@gmail.com on 20 Jan 2012 at 5:52

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. Did you experience the memory leak when using 
finishOpenedActivities()?

Original comment by renasr...@gmail.com on 21 Jan 2012 at 8:23

GoogleCodeExporter commented 9 years ago
It closed my application when I tried running finishOpenedActivities() in the 
loop during my test. The code for that method appears to close the current 
activity. I need a way to remove only references to activities that have been 
closed so they can be garbage collected.

Original comment by bjackson...@gmail.com on 21 Jan 2012 at 2:18

GoogleCodeExporter commented 9 years ago
Thanks. This will be implemented in the next release. 

Original comment by renasr...@gmail.com on 23 Jan 2012 at 7:22

GoogleCodeExporter commented 9 years ago
This has been implemented in Robotium 3.2. 

Original comment by renasr...@gmail.com on 10 Apr 2012 at 6:47