How to avoid java.lang.OutOfMemoryError?

后端 未结 2 2053
夕颜
夕颜 2021-01-24 01:43

I have two simple java codes.The first one defines constant power as power = a.pow(b);

import java.math.BigInteger;    
public class FermatOne    
{    
    publ         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 01:58

    It's just a guess, but BigInteger.ONE.shiftLeft(332192810); will internally create an int array of length x + 10381025. Since an int is 4 bytes big you'll get about 40 mega bytes of data just for that one call. I assume the other calls copy that data around and thus you get that high a memory consumption.

提交回复
热议问题