memory leak when tests close and restart appliction several times

10 views
Skip to first unread message

jalexan

unread,
Apr 21, 2009, 5:18:50 PM4/21/09
to Auto-android
Hi, All! Using 'ddms' and repeatably clicking SysInfo -> Update from
Device helped me find a memory leak. So we have 9 JUnit test cases
spread amongst 4 files, and we run them using positron in eclipse.
After EACH test
cases finishes, our application is exiting; and it restarts again for
the next test case. So for now, that's 9 times our app is closing and
restarting, which would be fine, except that each time it close it
leaks memory so that there is less available for the next test. All
we have for @before and @after is this:

@Before
public void setUp() {
System.gc(); // <-------- TRIED TO SEE IF THIS WOULD
HELP, BUT IT
DIDN'T
startActivity("com.yellowpages.android.ypmobile",
"com.yellowpages.android.ypmobile.YPM");
waitForStartup();
}

@After
public void postTest() {
if (wait_post_test) {
waitFor("class.simpleName", "BASIC_TIMEOUT",
timeout_in_ms);
}
}

Questions:
1. What's the proper solution? Find a way to only start the app ONE
time then run all tests? Or fix the leak?
2. To fix the leak, is there something we're missing/forgetting to do
in the @After method?
3. As a quick fix, is there somewhere particular in the positron code
that I can do a garbage collect() that might help?

Note: Restarting the app several times on a real device doesn't cause
a problem. Only when positron runs it in an emulator do we see the
problem. Any help is appreciated.

Thanks,

Julie

Phil Smith

unread,
Apr 21, 2009, 6:18:57 PM4/21/09
to autoa...@googlegroups.com
This problem sounds related to issue 7 (
http://code.google.com/p/autoandroid/issues/detail?id=7 ). In both
cases positron doesn't know how to properly kill an app to restart it.
It can shut down all its activities, but the hosting process (and
apparently some global UI state) will survive. I doubt triggering a
garbage collection in the device would help much, but it might be
worth a try.

If instead you want to disable exiting the app after every test, take
a look at the unit test super class:
http://code.google.com/p/autoandroid/source/browse/trunk/positron/src/main/java/com/googlecode/autoandroid/positron/junit4/TestCase.java

That super class is fairly dumb, on purpose. It creates a
PositronClient which will deal with talking to the instrumentation on
the device, and delegates a bunch of convenience calls to it. It also
(line 25) declares an @After tearDown() which calls finishAll(). This
finishAll() call is what (fails to completely) kill the app. You
should be able to easily override the method or swap in your own test
super class (or abandon junit altogether if you have the itch.)
Reply all
Reply to author
Forward
0 new messages