Java lang outofmemoryerror java heap space tlauncher

How to deal with «java.lang.OutOfMemoryError: Java heap space» error?

I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space 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 Ergonomics in the 5.0 Java Virtual Machine and others saying on Windows machine the JVM defaults max heap size as 64MB . Given this situation, how should I deal with this constraint? I could increase the max heap size using command line option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some finite max does not ultimately get rid of the issue. 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. If you could point me to details of above ideas or some alternatives like automatic virtual memory, extending heap size dynamically, that will be great.

Читайте также:  Определение Adblock

The default max heap size of 64 MB is from before J2SE 5.0. For J2SE 8.0 information, see «Garbage Collector Ergonomics» at docs.oracle.com/javase/8/docs/technotes/guides/vm/… .

If you landed here because every OOM question is duped to this one, make sure you also check out: stackoverflow.com/questions/299659/… It provides the solution for cleaning up memory references ‘just in time’ before the OOM. SoftReferences may be the tool that solves your actual problem.

The Sun/Oracle JVM has always been quite rigid about specifying the amount memory to use (and having some interesting defaults if left on its own). That was one of the nice things of the Microsoft JVM back then — it was fast and it could use whatever memory the machine had.

31 Answers 31

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 2GB (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).

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 no longer are using, or allocating many objects when you could reuse 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.

Читайте также:  Opencart убрать index php route common home

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» http://www.khelekore.org/jmp/.

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.

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.

Источник

Не работает кнопка TL Mods в Tlauncher. Что делать?

Ранее всё открывалось и работало прекрасно.
В консоли разработчика появляется это :
Starting garbage collector: 122 / 225 MB
Garbage collector completed: 38 / 226 MB
Starting garbage collector: 117 / 225 MB
OutOfMemory error has occurred, solving.
Garbage collector completed: 39 / 224 MB
Starting garbage collector: 39 / 224 MB
Garbage collector completed: 39 / 215 MB
Starting garbage collector: 117 / 223 MB
OutOfMemory error has occurred, solving.
GC is unable to reduce memory usage
Garbage collector completed: 39 / 225 MB
Hidden exception in thread ExtendedThread#236
java.lang.OutOfMemoryError: Java heap space
Thread called by: org.tlauncher.util.async.ExtendedThread$ExtendedThreadCaller
at org.tlauncher.util.async.ExtendedThread.(ExtendedThread.java:16)
at org.tlauncher.util.async.ExtendedThread.(ExtendedThread.java:20)
at org.tlauncher.util.async.RunnableThread.(RunnableThread.java:7)
at org.tlauncher.util.async.AsyncThread$1.newThread(AsyncThread.java:12)
at java.util.concurrent.ThreadPoolExecutor$Worker.(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.addWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source)
at org.tlauncher.util.async.AsyncThread.execute(AsyncThread.java:17)
at org.tlauncher.tlauncher.ui.login.buttons.ModpackButton$1.actionPerformed(ModpackButton.java:27)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Источник

How to Fix java.lang.OutOfMemoryError in Minecraft

When you’re joining a Minecraft server or your singleplayer world, you might encounter a set of errors. Let’s find out how to fix java.lang.OutOfMemoryError in Minecraft, which is pretty common with low-end computers.

What Kind of Error Is java.lang.OutOfMemoryError?

Encountering java.lang.OutOfMemoryError in Minecraft

As the name of the error suggests, it’s a memory-related issue. This means that you either don’t have enough space in your computer, or Minecraft can’t use enough RAM. It gets way more complicated than this, though, so let’s check out some solutions.

How to Fix the Minecraft java.lang.OutOfMemoryError Error?

Many Minecraft errors can simply be fixed if you do the following:

This will usually be enough to fix java.lang.OutOfMemoryError or any other error. But if the issue persists, you’ll have to try more advanced solutions. Thankfully, there are a few ways to fix this error.

Change Your Profile’s JVM Arguments

Changing the JVM Arguments

Changing your profile’s JVM arguments will allow you to allocate more RAM to Minecraft. The process is pretty simple, and it can be done straight from the Minecraft Launcher:

  1. Open the Minecraft Launcher.
  2. Click on Installations.
  3. Select your Minecraft version, click on the 3 dots, and select “Edit”.
  4. At the bottom of the page, select “More Options”.

At this point, you should see a “Java Executable” and a “JVM Arguments” line. The first argument on the latter should be the following: “-Xmx#G”, or “-Xmx#M”.

This is the amount of RAM you want to allocate to Minecraft (with M symbolizing megabytes and G symbolizing gigabytes). So, simply input a larger number according to how much RAM you have (i.e. If you have 8GBs of RAM, allocating 2-3 for Minecraft should be enough).

Delete _JAVA_OPTIONS in Environmental Variables

Finding the JAVA_OPTIONS in Environmental Variables

Oftentimes, other software might create a variable to restrict the RAM allocation for Java programs. Deleting this is similar to fixing the JNI Error in Minecraft:

  1. Press the Windows+R key, type “sysdm.cpl”, and press Enter.
  2. Select “Advanced” at the top, and click on “Environment Variables”.

You should locate a _JAVA_OPTIONS variable under “System Variables”, which you’ll need to delete. To do this, click on it and select “Delete”. Once that’s done, restart your computer to see if the java.lang.OutOfMemoryError persists.

Reinstall Java

If all else fails to fix the error, reinstalling Java should help you out. You can get this done quickly by downloading the Java uninstall tool and installing the latest Java version.

Upgrade Your Device’s RAM

Since the error is memory-related, you might need to upgrade your hardware. If none of the software fixes I mentioned above worked for you, you’ll need additional RAM sticks to run your server or world.

Conclusion

These solutions have hopefully helped you fix java.lang.OutOfMemoryError in Minecraft. You could try reinstalling the game if the error still troubles you. Or, you can check out one of the numerous threads on this issue on the Minecraft Forum for additional help.

Источник

Как справиться с ошибкой «java.lang.OutOfMemoryError: Java heap space»

Ошибка «java.lang.OutOfMemoryError: Java heap space» – это типичная проблема, с которой сталкиваются разработчики на Java. Это случается, когда виртуальная машина Java (JVM) не может выделить объекту достаточно памяти из кучи. Куча – это область памяти, выделенная JVM для хранения объектов.

Примером может служить ситуация, когда создается большое количество объектов, и все они хранятся в памяти. Например, при чтении большого количества файлов без последующего освобождения памяти. Если количество доступной памяти исчерпано, то JVM генерирует ошибку OutOfMemoryError.

Прежде всего, стоит быть внимательным к использованию памяти и стараться её экономить.

Однако, если проблему не удается решить на этапе написания кода, есть несколько способов обойти ограничение:

  1. Увеличение максимального размера кучи. Это можно сделать, установив параметр командной строки -Xmx . Например, -Xmx512m устанавливает максимальный размер кучи в 512 мегабайт. Но стоит помнить, что увеличение размера кучи до бесконечности не решит проблему, если есть утечка памяти в программе.
  2. Сохранение объектов на диск. Это может быть полезно, если программа работает с большим объемом данных, которые не нужны в памяти все время. Объекты можно сериализовать и сохранить на диск, а затем загрузить обратно, когда они понадобятся.
  3. Использование виртуальной памяти. В некоторых случаях можно использовать виртуальную память для увеличения доступного пространства кучи.

Лучшим решением будет комбинация этих методов, а также оптимизация кода для более эффективного использования памяти.

Источник

Оцените статью