question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.OutOfMemoryError: Java heap space when adding file

See original GitHub issue

When adding a “large” file of 100M got this error

SO Windows

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3236) at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118) at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93) at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153) at sun.net.www.http.PosterOutputStream.write(PosterOutputStream.java:78) at io.ipfs.api.Multipart.addFilePart(Multipart.java:102) at io.ipfs.api.IPFS.add(IPFS.java:83) at io.ipfs.api.IPFS.add(IPFS.java:74) at io.ipfs.api.IPFS.add(IPFS.java:70) IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001"); NamedStreamable streamable = new NamedStreamable.FileWrapper(new File("D:\\testfile")); List<MerkleNode> addParts = ipfs.add(streamable);

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
Clay-Fergusoncommented, Sep 7, 2020

@avanaur yeah with any kind of file transfers or streaming in Java you have to be sure there’s absolutely nowhere in the handling that there’s a byte array being used, or it will blow up memory on massive files for sure.

Also there’s more to the 4096 number than just a suggested number. The streaming apis buffer sizes at the lower levels of networking system code all use 4096, so everyone uses that size for any internet streaming because everything lines up perfectly with no unnecessary buffering or waiting. 4096 is widely accepted as the best number in most cases.

1reaction
avanaurcommented, Sep 2, 2018

Having this issue as well.

Seems to be fixed if to add httpConn.setChunkedStreamingMode(1024 * 1024 * 10); on Multipart contructor

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with "java.lang.OutOfMemoryError: Java heap ...
I would like to add recommendations from oracle trouble shooting article. Exception in thread thread_name: java.lang.OutOfMemoryError: Java heap space.
Read more >
java.lang.OutOfMemoryError: Java heap space - Plumbr
The java.lang.OutOfMemoryError: Java heap space error will be triggered when the application attempts to add more data into the heap space area, ...
Read more >
3.2 Understand the OutOfMemoryError Exception
Cause: The detail message Java heap space indicates object could not be allocated in the Java heap. This error does not necessarily imply...
Read more >
2 solution of java.lang.OutOfMemoryError in Java - Javarevisited
OutOfMemoryError in Java is a subclass of java.lang.VirtualMachineError and JVM throws java.lang.OutOfMemoryError when it ran out of memory in the heap.
Read more >
Java.lang.outofmemoryerror: java heap space - Javatpoint
Java.lang.outofmemoryerror: java heap space ... The name of the error itself conveys that it is an out-of-memory error where the JVM throws such...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found