<p>I am writing a client-side <strong>Swing</strong> application (graphical font designer) on <strong>Java 5</strong>. Recently, I am running into <code>java.lang.OutOfMemoryError: Java heap space</code> error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found <a href="http://java.sun.com/docs/hotspot/gc5.0/ergo5.html" rel="noreferrer">Ergonomics in the 5.0 Java Virtual Machine</a> and others saying on Windows machine the JVM defaults max heap size as <code>64MB</code>.</p>

<p>Given this situation, how should I deal with this constraint?</p>

<p>I could increase the <strong>max heap size</strong> using <strong>command line</strong> option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some <strong>finite</strong> max does not <strong>ultimately</strong> get rid of the issue.</p>

<p>I could rewrite some of my code to persist objects to file system frequently (using database is the same thing) to free up the memory. It could work, but it's probably a lot work too.</p>

<p>If you could point me to details of above ideas or some alternatives like <strong>automatic virtual memory, extending heap size dynamically</strong>, that will be great.</p>

[{'answer_id': 37349, 'author': 'Ben Childs', 'author_id': 2925, 'author_profile': 'https://Stackoverflow.com/users/2925', 'pm_score': 9, 'selected': True, 'text': '<p>Ultimately you always have a finite max of heap to use no matter what platform you are running on. In Windows 32 bit this is around <code>2GB</code> (not specifically heap but total amount of memory per process). It just happens that Java chooses to make the default smaller (presumably so that the programmer can\'t create programs that have runaway memory allocation without running into this problem and having to examine exactly what they are doing).</p>\n\n<p>So this given there are several approaches you could take to either determine what amount of memory you need or to reduce the amount of memory you are using. One common mistake with garbage collected languages such as Java or C# is to keep around references to objects that you <strong>no longer</strong> are using, or allocating many objects when you could <strong>reuse</strong> them instead. As long as objects have a reference to them they will continue to use heap space as the garbage collector will not delete them.</p>\n\n<p>In this case you can use a Java memory profiler to determine what methods in your program are allocating large number of objects and then determine if there is a way to make sure they are no longer referenced, or to not allocate them in the first place. One option which I have used in the past is "JMP" <a href="http://www.khelekore.org/jmp/" rel="noreferrer">http://www.khelekore.org/jmp/</a>.</p>\n\n<p>If you determine that you are allocating these objects for a reason and you need to keep around references (depending on what you are doing this might be the case), you will just need to increase the max heap size when you start the program. However, once you do the memory profiling and understand how your objects are getting allocated you should have a better idea about how much memory you need. </p>\n\n<p>In general if you can\'t guarantee that your program will run in some finite amount of memory (perhaps depending on input size) you will always run into this problem. Only after exhausting all of this will you need to look into caching objects out to disk etc. At this point you should have a very good reason to say "I need Xgb of memory" for something and you can\'t work around it by improving your algorithms or memory allocation patterns. Generally this will only usually be the case for algorithms operating on large datasets (like a database or some scientific analysis program) and then techniques like caching and memory mapped IO become useful.</p>\n'}, {'answer_id': 37466, 'author': 'David Webb', 'author_id': 3171, 'author_profile': 'https://Stackoverflow.com/users/3171', 'pm_score': 7, 'selected': False, 'text': '<p>Run Java with the command-line option <code>-Xmx</code>, which sets the <em>maximum</em> size of the heap.</p>\n\n<p><a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#nonstandard" rel="noreferrer">See here for details</a>.</p>\n'}, {'answer_id': 186390, 'author': 'kohlerm', 'author_id': 26056, 'author_profile': 'https://Stackoverflow.com/users/26056', 'pm_score': 4, 'selected': False, 'text': '<p>Yes, with <code>-Xmx</code> you can configure more memory for your JVM. \nTo be sure that you don\'t leak or waste memory. Take a heap dump and use <a href="http://www.eclipse.org/mat/" rel="nofollow noreferrer">the Eclipse Memory Analyzer</a> to analyze your memory consumption. </p>\n'}, {'answer_id': 186957, 'author': 'Leigh', 'author_id': 26061, 'author_profile': 'https://Stackoverflow.com/users/26061', 'pm_score': 3, 'selected': False, 'text': '<p>If you need to monitor your memory usage at runtime, the <code>java.lang.management</code> package offers <code>MBeans</code> that can be used to monitor the memory pools in your VM (eg, eden space, tenured generation etc), and also garbage collection behaviour.</p>\n\n<p>The free heap space reported by these MBeans will vary greatly depending on GC behaviour, particularly if your application generates a lot of objects which are later GC-ed. One possible approach is to monitor the free heap space after each full-GC, which you may be able to use to make a decision on freeing up memory by persisting objects.</p>\n\n<p>Ultimately, your best bet is to limit your memory retention as far as possible whilst performance remains acceptable. As a previous comment noted, memory is always limited, but your app should have a strategy for dealing with memory exhaustion. </p>\n'}, {'answer_id': 747593, 'author': 'David', 'author_id': 57246, 'author_profile': 'https://Stackoverflow.com/users/57246', 'pm_score': 5, 'selected': False, 'text': '<p>Big caveat ---- at my office, we were finding that (on some windows machines) we could not allocate more than 512m for Java heap. This turned out to be due to the Kaspersky anti-virus product installed on some of those machines. After uninstalling that AV product, we found we could allocate at least 1.6gb,   i.e,   <code>-Xmx1600m</code> (m is mandatory other wise it will lead to another error "Too small initial heap") works.</p>\n\n<p>No idea if this happens with other AV products but presumably this is happening because the AV program is reserving a small block of memory in every address space, thereby preventing a single really large allocation. </p>\n'}, {'answer_id': 880998, 'author': 'Thorbjørn Ravn Andersen', 'author_id': 53897, 'author_profile': 'https://Stackoverflow.com/users/53897', 'pm_score': 3, 'selected': False, 'text': '<p>Note that if you need this in a deployment situation, consider using Java WebStart (with an "ondisk" version, not the network one - possible in Java 6u10 and later) as it allows you to specify the various arguments to the JVM in a cross platform way.</p>\n\n<p>Otherwise you will need an operating system specific launcher which sets the arguments you need.</p>\n'}, {'answer_id': 3500230, 'author': 'mwangi', 'author_id': 422550, 'author_profile': 'https://Stackoverflow.com/users/422550', 'pm_score': 3, 'selected': False, 'text': "<p>I read somewhere else that you can try - catch java.lang.OutOfMemoryError and on the catch block, you can free all resources that you know might use a lot of memory, close connections and so forth, then do a <code>System.gc()</code> then re-try whatever you were going to do.</p>\n\n<p>Another way is this although, i don't know whether this would work, but I am currently testing whether it will work on my application.</p>\n\n<p>The Idea is to do Garbage collection by calling System.gc() which is known to increase free memory. You can keep checking this after a memory gobbling code executes.</p>\n\n<pre><code>//Mimimum acceptable free memory you think your app needs\nlong minRunningMemory = (1024*1024);\n\nRuntime runtime = Runtime.getRuntime();\n\nif(runtime.freeMemory()&lt;minRunningMemory)\n System.gc();\n</code></pre>\n"}, {'answer_id': 3819680, 'author': 'SoulWanderer', 'author_id': 459303, 'author_profile': 'https://Stackoverflow.com/users/459303', 'pm_score': 1, 'selected': False, 'text': "<p>If you keep on allocating &amp; keeping references to object, you will fill up any amount of memory you have.</p>\n\n<p>One option is to do a transparent file close &amp; open when they switch tabs (you only keep a pointer to the file, and when the user switches tab, you close &amp; clean all the objects... it'll make the file change slower... but...), and maybe keep only 3 or 4 files on memory.</p>\n\n<p>Other thing you should do is, when the user opens a file, load it, and intercept any OutOfMemoryError, then (as it is not possible to open the file) close that file, clean its objects and warn the user that he should close unused files.</p>\n\n<p>Your idea of dynamically extending virtual memory doesn't solve the issue, for the machine is limited on resources, so you should be carefull &amp; handle memory issues (or at least, be carefull with them).</p>\n\n<p>A couple of hints i've seen with memory leaks is:</p>\n\n<p>--> Keep on mind that if you put something into a collection and afterwards forget about it, you still have a strong reference to it, so nullify the collection, clean it or do something with it... if not you will find a memory leak difficult to find.</p>\n\n<p>--> Maybe, using collections with weak references (weakhashmap...) can help with memory issues, but you <strong>must</strong> be carefull with it, for you might find that the object you look for has been collected.</p>\n\n<p>--> Another idea i've found is to develope a persistent collection that stored on database objects least used and transparently loaded. This would probably be the best approach... </p>\n"}, {'answer_id': 5121287, 'author': 'allenhwkim', 'author_id': 454252, 'author_profile': 'https://Stackoverflow.com/users/454252', 'pm_score': 7, 'selected': False, 'text': '<p>You could specify <strong>per</strong> project how much heap space your project wants</p>\n\n<p>Following is for <strong>Eclipse Helios/Juno/Kepler</strong>:</p>\n\n<p>Right mouse click on</p>\n\n<pre><code> Run As - Run Configuration - Arguments - Vm Arguments, \n</code></pre>\n\n<p>then add this</p>\n\n<pre><code>-Xmx2048m\n</code></pre>\n'}, {'answer_id': 5954865, 'author': 'Soumya Sandeep Mohanty', 'author_id': 747409, 'author_profile': 'https://Stackoverflow.com/users/747409', 'pm_score': 3, 'selected': False, 'text': '<p>I have faced same problem from java heap size.</p>\n\n<p>I have two solutions if you are using java 5(1.5).</p>\n\n<ol>\n<li><p>just install jdk1.6 and go to the preferences of eclipse and set the jre path of jav1 1.6 as you have installed.</p></li>\n<li><p>Check your VM argument and let it be whatever it is.\njust add one line below of all the arguments present in VM arguments as \n-Xms512m  -Xmx512m -XX:MaxPermSize=...m(192m).</p></li>\n</ol>\n\n<p>I think it will work...</p>\n'}, {'answer_id': 6299069, 'author': 'loveall', 'author_id': 791703, 'author_profile': 'https://Stackoverflow.com/users/791703', 'pm_score': 5, 'selected': False, 'text': '<p>VM arguments worked for me in eclipse. If you are using eclipse version 3.4, do the following</p>\n\n<p>go to <code>Run --&gt; Run Configurations --&gt;</code> then select the project under maven build --> then select the tab "JRE" --> then enter <code>-Xmx1024m</code>.</p>\n\n<p>Alternatively you could do <code>Run --&gt; Run Configurations --&gt; select the "JRE" tab --&gt;</code> then enter -<code>Xmx1024m</code></p>\n\n<p>This should increase the memory heap for all the builds/projects. The above memory size is 1 GB. You can optimize the way you want.</p>\n'}, {'answer_id': 7297504, 'author': 'chaukssey', 'author_id': 927269, 'author_profile': 'https://Stackoverflow.com/users/927269', 'pm_score': 3, 'selected': False, 'text': '<p>Easy way to solve <code>OutOfMemoryError</code> in java is to increase the maximum heap size by using JVM options <code>-Xmx512M</code>, this will immediately solve your OutOfMemoryError. This is my preferred solution when I get OutOfMemoryError in Eclipse, Maven or ANT while building project because based upon size of project you can easily ran out of Memory.</p>\n\n<p>Here is an example of increasing maximum heap size of JVM, Also its better to keep -Xmx to -Xms ration either 1:1 or 1:1.5 if you are setting heap size in your java application.</p>\n\n<p><code>export JVM_ARGS="-Xms1024m -Xmx1024m"</code></p>\n\n<p><a href="http://javarevisited.blogspot.com/2011/09/javalangoutofmemoryerror-permgen-space.html" rel="noreferrer">Reference Link</a></p>\n'}, {'answer_id': 19222984, 'author': 'Pradip Bhatt', 'author_id': 2098900, 'author_profile': 'https://Stackoverflow.com/users/2098900', 'pm_score': 4, 'selected': False, 'text': '<p>Follow below steps:</p>\n\n<ol>\n<li><p>Open <code>catalina.sh</code> from tomcat/bin.</p></li>\n<li><p>Change JAVA_OPTS to </p>\n\n<pre><code>JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m \n-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m \n-XX:MaxPermSize=256m -XX:+DisableExplicitGC"\n</code></pre></li>\n<li><p>Restart your tomcat</p></li>\n</ol>\n'}, {'answer_id': 21494341, 'author': 'PeakGen', 'author_id': 1379286, 'author_profile': 'https://Stackoverflow.com/users/1379286', 'pm_score': 6, 'selected': False, 'text': '<p>Increasing the heap size is not a "fix" it is a "plaster", 100% temporary. It will crash again in somewhere else. To avoid these issues, write high performance code.</p>\n\n<ol>\n<li>Use local variables wherever possible.</li>\n<li>Make sure you select the correct object (EX: Selection between String, StringBuffer and StringBuilder)</li>\n<li>Use a good code system for your program(EX: Using static variables VS non static variables)</li>\n<li>Other stuff which could work on your code.</li>\n<li>Try to move with multy THREADING</li>\n</ol>\n'}, {'answer_id': 36162516, 'author': 'Ravindra babu', 'author_id': 4999394, 'author_profile': 'https://Stackoverflow.com/users/4999394', 'pm_score': 5, 'selected': False, 'text': '<p>I would like to add recommendations from oracle <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html" rel="noreferrer">trouble shooting</a> article.</p>\n\n<p>Exception in thread thread_name: <strong>java.lang.OutOfMemoryError: Java heap space</strong></p>\n\n<blockquote>\n  <p>The detail message Java heap space indicates object could not be allocated in the Java heap. This error does not necessarily imply a memory leak</p>\n</blockquote>\n\n<p><em>Possible causes:</em></p>\n\n<ol>\n<li><p><em>Simple configuration issue</em>, where the specified heap size is insufficient for the application.</p></li>\n<li><p><em>Application is unintentionally holding references to objects</em>, and this prevents the objects from being garbage collected.</p></li>\n<li><p><em>Excessive use of finalizers</em>. </p></li>\n</ol>\n\n<blockquote>\n  <p>One other potential source of this error arises with applications that make excessive use of finalizers. If a class has a finalize method, then objects of that type do not have their space reclaimed at garbage collection time</p>\n</blockquote>\n\n<p>After <em>garbage collection</em>, the objects are queued for <em>finalization</em>, which occurs at a later time.  <em>finalizers</em> are executed by a daemon thread that services the finalization queue. If the <em>finalizer</em> thread cannot keep up with the finalization queue, then the Java heap could fill up and this type of <strong>OutOfMemoryError</strong> exception would be thrown. </p>\n\n<p>One scenario that can cause this situation is when an application creates <em>high-priority threads</em> that cause the <em>finalization</em> queue to increase at a rate that is faster than the rate at which the finalizer thread is servicing that queue.</p>\n'}, {'answer_id': 37460287, 'author': 'Musa', 'author_id': 4720910, 'author_profile': 'https://Stackoverflow.com/users/4720910', 'pm_score': 3, 'selected': False, 'text': '<p>By default for development JVM uses small size and small config for other performance related features. But for production you can tune e.g. (In addition it Application Server specific config can exist) -> (If there still isn\'t enough memory to satisfy the request and the heap has already reached the maximum size, an OutOfMemoryError will occur)</p>\n\n<pre><code>-Xms&lt;size&gt;        set initial Java heap size\n-Xmx&lt;size&gt;        set maximum Java heap size\n-Xss&lt;size&gt;        set java thread stack size\n\n-XX:ParallelGCThreads=8\n-XX:+CMSClassUnloadingEnabled\n-XX:InitiatingHeapOccupancyPercent=70\n-XX:+UnlockDiagnosticVMOptions\n-XX:+UseConcMarkSweepGC\n-Xms512m\n-Xmx8192m\n-XX:MaxPermSize=256m (in java 8 optional)\n</code></pre>\n\n<p>For example: On linux Platform for production mode preferable settings. </p>\n\n<p>After downloading and configuring server with this way <a href="http://www.ehowstuff.com/how-to-install-and-setup-apache-tomcat-8-on-centos-7-1-rhel-7/" rel="nofollow noreferrer">http://www.ehowstuff.com/how-to-install-and-setup-apache-tomcat-8-on-centos-7-1-rhel-7/</a>  </p>\n\n<p>1.create setenv.sh file on folder /opt/tomcat/bin/</p>\n\n<pre><code>   touch /opt/tomcat/bin/setenv.sh\n</code></pre>\n\n<p>2.Open and write this params for setting preferable mode.</p>\n\n<pre><code>nano  /opt/tomcat/bin/setenv.sh \n\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:ParallelGCThreads=8"\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:+CMSClassUnloadingEnabled"\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:InitiatingHeapOccupancyPercent=70"\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:+UnlockDiagnosticVMOptions"\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:+UseConcMarkSweepGC"\nexport CATALINA_OPTS="$CATALINA_OPTS -Xms512m"\nexport CATALINA_OPTS="$CATALINA_OPTS -Xmx8192m"\nexport CATALINA_OPTS="$CATALINA_OPTS -XX:MaxMetaspaceSize=256M"\n</code></pre>\n\n<p>3.<code>service tomcat restart</code></p>\n\n<blockquote>\n  <p>Note that the JVM uses more memory than just the heap. For example\n  Java methods, thread stacks and native handles are allocated in memory\n  separate from the heap, as well as JVM internal data structures.</p>\n</blockquote>\n'}, {'answer_id': 43212058, 'author': 'satish', 'author_id': 5281441, 'author_profile': 'https://Stackoverflow.com/users/5281441', 'pm_score': 1, 'selected': False, 'text': '<p>If this issue is happening in Wildfly 8 and JDK1.8,then we need to specify MaxMetaSpace settings instead of PermGen settings.</p>\n\n<p>For example we need to add below configuration in setenv.sh file of wildfly.\n<code>JAVA_OPTS="$JAVA_OPTS -XX:MaxMetaspaceSize=256M"</code></p>\n\n<p>For more information, please check <a href="http://techno-terminal.blogspot.in/2017/03/wildfly-82-heap-issue.html" rel="nofollow noreferrer">Wildfly Heap Issue</a></p>\n'}, {'answer_id': 44509883, 'author': 'htlbydgod', 'author_id': 7533664, 'author_profile': 'https://Stackoverflow.com/users/7533664', 'pm_score': 2, 'selected': False, 'text': "<p>Regarding to netbeans, you could set max heap size to solve the problem. </p>\n\n<p>Go to 'Run', then --> 'Set Project Configuration' --> 'Customise' --> 'run' of its popped up window --> 'VM Option' --> fill in '-Xms2048m -Xmx2048m'.</p>\n"}, {'answer_id': 58809609, 'author': 'nccc', 'author_id': 1114052, 'author_profile': 'https://Stackoverflow.com/users/1114052', 'pm_score': 0, 'selected': False, 'text': '<p>If everything else fails, in addition to increasing the max heap size try also increasing the swap size. For Linux, as of now, relevant instructions can be found in <a href="https://linuxize.com/post/create-a-linux-swap-file/" rel="nofollow noreferrer">https://linuxize.com/post/create-a-linux-swap-file/</a>.</p>\n\n<p>This can help if you\'re e.g. compiling something big in an embedded platform.</p>\n'}, {'answer_id': 63924199, 'author': 'Antonin Dioulo', 'author_id': 4998760, 'author_profile': 'https://Stackoverflow.com/users/4998760', 'pm_score': 0, 'selected': False, 'text': '<p>if you got this error when you launch eclipse birt\n1- you will go in the file of the eclipse configuration\n2- you must open eclipse.init\n3- modified the RAM memory, you can increase this, i give an example.</p>\n<p>my old information was :\n-Xmx128m\n-XX:MaxPermSize=128m</p>\n<p>the new modification that i opered :</p>\n<p>-Xmx512m\n-XX:MaxPermSize=512m</p>\n<p>this modification will permit me to resolve java heap space when i launch my report in my browser.</p>\n<p>Thanks</p>\n'}, {'answer_id': 64514498, 'author': 'Nima Ganji', 'author_id': 10589851, 'author_profile': 'https://Stackoverflow.com/users/10589851', 'pm_score': 3, 'selected': False, 'text': "<p>In android studio add/change this line at the end of <code>gradle.properties (Global Properties)</code>:</p>\n<pre><code>...\norg.gradle.jvmargs=-XX\\:MaxHeapSize\\=1024m -Xmx1024m \n</code></pre>\n<p>if it doesn't work you can retry with bigger than 1024 heap size.</p>\n"}, {'answer_id': 66625139, 'author': 'itzo', 'author_id': 4823237, 'author_profile': 'https://Stackoverflow.com/users/4823237', 'pm_score': 2, 'selected': False, 'text': '<p>Android Studio</p>\n<p>File -&gt; Invalidate Caches and Restart solved it for me :)</p>\n'}, {'answer_id': 67222160, 'author': 'Haranath Boggarapu', 'author_id': 11779689, 'author_profile': 'https://Stackoverflow.com/users/11779689', 'pm_score': 1, 'selected': False, 'text': '<p>Java OOM Heap space issue can also arise when your DB connection pool got full.</p>\n<p>I faced this issue because of my Hikari Connection pool (when upgraded to Spring boot 2.4.*) was full and not able to provide connections anymore (all active connections are still pending to fetch results from database).</p>\n<p>Issue is some of our native queries in JPA Repositories contain <strong>ORDER BY ?#{#pageable}</strong> which takes a very long time to get results when upgraded.</p>\n<p>Removed <strong>ORDER BY ?#{#pageable}</strong> from all the native queries in JPA repositories and OOM heap space issue along with connection pool issue got resolved.</p>\n'}, {'answer_id': 67734602, 'author': 'samuelru', 'author_id': 7829977, 'author_profile': 'https://Stackoverflow.com/users/7829977', 'pm_score': 1, 'selected': False, 'text': '<p>If this error occurs right after execution of your junit tests, then you should execute <strong>Build</strong> -&gt; <strong>Rebuild Project</strong>.</p>\n'}, {'answer_id': 68934961, 'author': 'CodingEra', 'author_id': 9920209, 'author_profile': 'https://Stackoverflow.com/users/9920209', 'pm_score': 3, 'selected': False, 'text': '<p>add the below code inside <strong>android/gradle.properties</strong>:</p>\n<pre><code>org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError\norg.gradle.daemon=true\norg.gradle.parallel=true\norg.gradle.configureondemand=true\n</code></pre>\n'}, {'answer_id': 68973465, 'author': 'Chukwunazaekpere', 'author_id': 12589424, 'author_profile': 'https://Stackoverflow.com/users/12589424', 'pm_score': 1, 'selected': False, 'text': '<p>If this error comes up during APK generation in react-native, cd into the android folder in your project and do:</p>\n<pre><code>./gradlew clean\n</code></pre>\n<p>then</p>\n<pre><code>./gradlew assembleRelease\n</code></pre>\n<p>If error persists, then, restart your machine.</p>\n'}, {'answer_id': 69098151, 'author': 'Muhammad Raqib', 'author_id': 4491818, 'author_profile': 'https://Stackoverflow.com/users/4491818', 'pm_score': 3, 'selected': False, 'text': '<p>If you came here to search this issue from REACT NATIVE.</p>\n<p>Then i guess you should do this</p>\n<pre><code>cd android/ &amp;&amp; ./gradlew clean &amp;&amp; cd ..\n</code></pre>\n'}, {'answer_id': 70096676, 'author': 'Talha Akbar', 'author_id': 7798091, 'author_profile': 'https://Stackoverflow.com/users/7798091', 'pm_score': 3, 'selected': False, 'text': '<p>Add this line to your gradle.properties file</p>\n<pre><code>org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8\n</code></pre>\n<p>It should work. You can change MaxPermSize accordingly to fix your heap problem</p>\n'}, {'answer_id': 70643906, 'author': 'Neeraj Singh', 'author_id': 1733810, 'author_profile': 'https://Stackoverflow.com/users/1733810', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using Android Studio just add these lines with <strong>gradle.properties</strong> file</p>\n<p>org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8</p>\n'}, {'answer_id': 71047778, 'author': 'Morteza', 'author_id': 13989422, 'author_profile': 'https://Stackoverflow.com/users/13989422', 'pm_score': 2, 'selected': False, 'text': '<p>In my case it solved by assigning more memory to <code>Shared build process heap size</code> in intellij settings.</p>\n<p>Go to intellij settings &gt; Compiler &gt; Shared build process heap size</p>\n<p><a href="https://i.stack.imgur.com/UV6Ii.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UV6Ii.png" alt="enter image description here" /></a></p>\n'}, {'answer_id': 73976373, 'author': 'edalvb', 'author_id': 10942128, 'author_profile': 'https://Stackoverflow.com/users/10942128', 'pm_score': 0, 'selected': False, 'text': '<p>In Intellij, it worked for me just by giving the &quot;Build Project&quot;</p>\n<p><a href="https://i.stack.imgur.com/runsu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/runsu.png" alt="enter image description here" /></a></p>\n'}]
['https://Stackoverflow.com/questions/37335', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3827/']