OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange

17.8k views Asked by At

This is the error that is thrown in the GWT DevMode console when passing an image base64 String (abour ~360KB in size) to a GWT method with String param:

java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Arrays.java:2694) at java.lang.String.(String.java:234) at java.lang.StringBuilder.toString(StringBuilder.java:405) at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$23._marshall1(MarshallerFactoryImpl.java:1310) at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$23.marshall(MarshallerFactoryImpl.java:1326) at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$23.marshall(MarshallerFactoryImpl.java:1) at org.jboss.errai.marshalling.client.marshallers.QualifyingMarshallerWrapper.doNotNullMarshall(QualifyingMarshallerWrapper.java:93) at org.jboss.errai.marshalling.client.marshallers.AbstractNullableMarshaller.marshall(AbstractNullableMarshaller.java:29) at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$24.marshall(MarshallerFactoryImpl.java:1402) at org.jboss.errai.marshalling.client.api.MarshallerFactoryImpl$24.marshall(MarshallerFactoryImpl.java:1) at org.jboss.errai.marshalling.client.Marshalling.toJSON(Marshalling.java:83) at org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper.toJSON(MarshallingWrapper.java:32) at org.jboss.errai.enterprise.client.jaxrs.JaxrsProxyLoaderImpl$1com_myapp_client_shared_service_PasteServiceImpl.createPaste(JaxrsProxyLoaderImpl.java:194) at com.myapp.client.local.PastePage.onPasteImage(PastePage.java:257) at com.myapp.client.local.PastePage$4$1.run(PastePage.java:162) at com.google.gwt.user.client.Timer.fire(Timer.java:149) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)

Looking at the logs it does not look like its a client-side issue, more of a marshalling issue.

2

There are 2 answers

1
Gerald Horton On BEST ANSWER

It simply means that the JVM ran out of memory. When this occurs, you basically have 2 choices:

  • Allow the JVM to use more memory using the -Xmx VM argument. For instance, to allow the JVM to use 1 GB (1024 MB) of memory

  • Improve/Fix the application so that it uses less memory

In many cases, like in the case of a memory leak, the second option is the only sound choice. A memory leak happens when the application keeps more and more references to objects and never releases them. The garbage collector will therefore never collect those objects and less and less free memory will be available until we reach the point where not enough free memory is available for the application to function normally. At this point, the JVM will throw an OOM.

Try this solution.

0
smallfatter On

suggest add the profile to capture the dump file when error occuring and using mat to analyse the finaly reason maybe helpful.