java.lang.OutOfMemoryError: Java heap space when adding file
See original GitHub issueWhen 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:
- Created 5 years ago
- Comments:6
Top GitHub Comments
@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.
Having this issue as well.
Seems to be fixed if to add
httpConn.setChunkedStreamingMode(1024 * 1024 * 10);
onMultipart
contructor