{"action":"created","issue":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/1700","labels_url":"https://api.github.com/repos/robolectric/robolectric/issues/1700/labels{/name}","comments_url":"https://api.github.com/repos/robolectric/robolectric/issues/1700/comments","events_url":"https://api.github.com/repos/robolectric/robolectric/issues/1700/events","html_url":"https://github.com/robolectric/robolectric/issues/1700","id":69674843,"number":1700,"title":"3.0-rc2 OutOfMemoryError PermGen space and hanging builds","user":{"login":"cameocoder","id":3324489,"avatar_url":"https://avatars.githubusercontent.com/u/3324489?v=3","gravatar_id":"","url":"https://api.github.com/users/cameocoder","html_url":"https://github.com/cameocoder","followers_url":"https://api.github.com/users/cameocoder/followers","following_url":"https://api.github.com/users/cameocoder/following{/other_user}","gists_url":"https://api.github.com/users/cameocoder/gists{/gist_id}","starred_url":"https://api.github.com/users/cameocoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cameocoder/subscriptions","organizations_url":"https://api.github.com/users/cameocoder/orgs","repos_url":"https://api.github.com/users/cameocoder/repos","events_url":"https://api.github.com/users/cameocoder/events{/privacy}","received_events_url":"https://api.github.com/users/cameocoder/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/robolectric/robolectric/labels/3.0","name":"3.0","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-20T20:35:15Z","updated_at":"2015-04-21T16:17:59Z","closed_at":null,"body":"I have a suite consisting of almost 2000 tests that work with Robolectric 2.4.  I have started updating the suite to work with 3.0-rc2 but I can only run about ~700 tests before they fail with an OutOfMemoryError or hang.  It seems that once I reach a certain size, the tests will fail.  For example I will run X tests successfully, then I will add a few more test classes and the suite will fail.  If I leave the newly added classes and remove some of the classes known to be successful, I can get a successful build again.\r\n\r\nThe conversion for the majority of tests was just a matter of using the RobolectricGradleTestRunner,  adding @Config line and fixing references to Robolectric classes that were moved.  Continuing to use RobolectricTestRunner instead of RobolectricGradleTestRunner fails in similar ways.\r\n\r\nThe following jvmargs are set in the gradle.properties file.  Increasing the memory options does not help:\r\norg.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8\r\n\r\nThere are a few failure scenarios I have seen:\r\n- Test execution hang with no output\r\n- \"OutOfMemoryError: PermGen space\" error followed by gradle stacktrace\r\n- One of the above or just test failure followed by a different class loading error each time:\r\n    [ERROR] couldn't load roboguice.activity.RoboActivity in org.robolectric.internal.bytecode.InstrumentingClassLoader@4d0ed336\r\n\r\n    [ERROR] couldn't load android.content.Context in org.robolectric.internal.bytecode.InstrumentingClassLoader@3e1cbf2e\r\n\r\n    [ERROR] couldn't load org.bouncycastle.jce.provider.BouncyCastleProvider in\r\norg.robolectric.internal.bytecode.InstrumentingClassLoader@6243e098\r\n\r\nIn all cases, just removing a few test classes will allow the tests to succeed.\r\n\r\nGiven I have a suite of testcases that work with 2.4 and work with 3.0-rc2 in batches of ~700 tests, It seems to point to something in the 3.0 changes that are causing these OOM errors."},"comment":{"url":"https://api.github.com/repos/robolectric/robolectric/issues/comments/94858569","html_url":"https://github.com/robolectric/robolectric/issues/1700#issuecomment-94858569","issue_url":"https://api.github.com/repos/robolectric/robolectric/issues/1700","id":94858569,"user":{"login":"mag","id":2266,"avatar_url":"https://avatars.githubusercontent.com/u/2266?v=3","gravatar_id":"","url":"https://api.github.com/users/mag","html_url":"https://github.com/mag","followers_url":"https://api.github.com/users/mag/followers","following_url":"https://api.github.com/users/mag/following{/other_user}","gists_url":"https://api.github.com/users/mag/gists{/gist_id}","starred_url":"https://api.github.com/users/mag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mag/subscriptions","organizations_url":"https://api.github.com/users/mag/orgs","repos_url":"https://api.github.com/users/mag/repos","events_url":"https://api.github.com/users/mag/events{/privacy}","received_events_url":"https://api.github.com/users/mag/received_events","type":"User","site_admin":false},"created_at":"2015-04-21T16:17:58Z","updated_at":"2015-04-21T16:17:58Z","body":"I have been working on a large app that was having these problems as well.\n\nWe recently switched over to Java 8, which eliminates perm gen altogether,\nand these problems went away. We are on Robolectric 2.4.\n\nMike\n\nOn Tue, Apr 21, 2015 at 8:04 AM, Jonathan Gerrish <notifications@github.com>\nwrote:\n\n> I've been seeing similar problems sporadically.\n>\n> What are your jvm permgen settings?\n> Did you specify a particular version of Android SDK to use?\n> What test runner(s) are you using?\n>\n> In Robolectric tests, especially where liberal use of Mockito is involved\n> requires a lot of permgen space due to all the generated classes. Probably\n> this is exasperated by newer and bigger android sdks. If you just moved\n> from 2.4 to 3.0 without any config changes then I think you've also moved\n> from emulateSdk = 18 to emulateSdk = 21 implicitly.\n>\n> Quick fixes would be to:-\n> 1) Bump your max permgen setting\n> 2) Set Robolectric config to use emulateSdk = 18 for all your tests (same\n> as the default in 2.4)\n>\n> The more involved was would be to check where this permgen space is going,\n> its possible there is a leak... I followed these instructions to get a\n> better understanding of possible issues and how to diagnose.\n>\n> https://cdivilly.wordpress.com/2012/04/23/permgen-memory-leak/\n>\n> When I checked yesterday, I found that one problem is when you are using\n> multiple test runner instances. Each one of them holds its own reference to\n> a current and previous (cached) SdkEnvironment which in turn holds a\n> reference to the instrumenting classloader which contains class definitions\n> for everything it has loaded. Too many of these and it soon maxes out perm\n> gen. You can test this by creating a custom test runner for each of your\n> tests.\n>\n> @erd <https://github.com/erd> this is one of the things that I was\n> chatting to you about yesterday\n>\n> The solution I think is to have a static (VM + test runner wide cache of\n> all SdkEnvironments) which means RobolectricTestRunner classes would share\n> this cache. It is probably better anyway these days as there are more\n> android versions to test against, more and more tests will have different\n> tests for different api levels.\n>\n> I'll try and submit a PR for that today but if I were you I would profile\n> your tests anyway, start by querying for\n>\n> select x from org.robolectric.internal.SdkEnvironment x\n>\n> How many are there? What objects are holding a reference to it?\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/robolectric/robolectric/issues/1700#issuecomment-94832232>\n> .\n>\n"}}