Tests consume a lot of memory

42 views
Skip to first unread message

Ivan Micanovic

unread,
Sep 3, 2019, 11:09:30 AM9/3/19
to Robolectric
Hi,

I have googled for this topic and I found other people encounter same issue.
Here I will give you some inputs from my side.

In my case I have discovered that running tests (we have about 1500 tests) consumes about 5GB at the end of executing.

Our setup is:
   - android studio 3.4.2
   - jdk 9
   - robolectirc 4.2
   - androidx


Obviously somewhere memory leaks.
For each test where we create activity, in @After we call 
        activity.onPause()
        activity.onStop()
        activity.onDestroy()
but it's not enough to prevent dispose some objects allocated during the executing test.

Also, I do some statistics using VisualVM tool and here is output:

unit test statistics.png



As you can see, almost 2.2GB are consumed in first line and (on this preview) robolectric objects allocated about 3.4 GB. Dose anyone know what I need to do in my tests to release that objects?
I assume the robolectric creates some of this objects when create Application object. If it's true then definitely I need to do something with Application instance in @After section. Does this make sense or I'm completely wrong?

Thanks in advance,
Ivan




Reply all
Reply to author
Forward
0 new messages