LoginSignup
1
0

More than 1 year has passed since last update.

【java】ヒープメモリエラー

Posted at

javaで下記エラーが出ました。
よくあるエラー。
java.lang.OutOfMemoryError: Java heap space

コードは下記

sample.java

//初期化
long n = 沢山;

//日付ループ
for(long i=0;i<n;i++){
    //SimpleDateFormatオブジェクト
    SimpleDateFormat sdf = new SimpleDateFormat(format);  //error
    //フォーマット指定あり
    System.out.println(sdf.format(date));
}

この通りに書いているわけではないですが、あるクラスの中でSimpleDateFormatを使用していて、サンプルデータ作成時にそのクラスをループで呼び出していたというものでした。
解決策としては、下記の様にクラスを開放して問題なく動作しました。

sample.java

//初期化
long n = 沢山;

//日付ループ
for(long i=0;i<n;i++){
    //SimpleDateFormatオブジェクト
    SimpleDateFormat sdf = new SimpleDateFormat(format);  //ok
    //フォーマット指定あり
    System.out.println(sdf.format(date));
    //クリア
    sdf = null;  //追記
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0